Crates.io | trait-stack |
lib.rs | trait-stack |
version | 0.1.3 |
source | src |
created_at | 2022-06-18 15:40:42.181977 |
updated_at | 2023-07-02 06:53:22.281297 |
description | Fast heterogeneous stack |
homepage | |
repository | https://github.com/storycraft/trait-stack/ |
max_upload_size | |
id | 608577 |
size | 30,026 |
Store trait object and vtable using two Vec.
Provides efficient heterogeneous list when the elements don't need to get resorted.
Vec<Box<dyn Trait>>
Vec<Box<dyn Trait>>
makes allocation per element. Inserting many objects can hurt performance due to allocation.
TraitStack
stack object to its inner vector. It makes moving element by index impossible and only can be used as stack. but very fast on insertion.
See diagram for detailed structure.
No support.
let mut stack = TraitStack::<dyn Debug>::new();
stack.push("str");
stack.push(1);
stack.push(28342.2);
println!("{:?}", stack); // Print ["str", 1, 28342.2]