1 unstable release
0.2.0 | Jul 2, 2023 |
---|---|
0.1.3 |
|
0.1.2 |
|
0.1.1 |
|
0.1.0 |
|
#2204 in Data structures
Used in sketch-2d
18KB
448 lines
UnsizedStack
Store unboxed DST objects
Provides efficient list when the elements don't need to get resorted for DST types.
NOTE:
UnsizedStack
relies on an unspecified fat pointer representation
Diagram
Each object is correctly padded.
Example
Trait object
use unsized_stack::UnsizedStack;
use std::fmt::Debug;
let mut stack = UnsizedStack::<dyn Debug>::new();
stack.push("str", |item| item as _);
stack.push(1, |item| item as _);
stack.push(28342.2, |item| item as _);
dbg!(stack); // Print stack = ["str", 1, 28342.2]
str
use unsized_stack::UnsizedStack;
use std::fmt::Debug;
let mut stack = UnsizedStack::<str>::new();
stack.push("str", |item| item as _);
stack.push("asdf", |item| item as _);
stack.push("abcd", |item| item as _);
dbg!(stack); // Print stack = ["str", "asdf", "abcd"]
slices
use unsized_stack::UnsizedStack;
use std::fmt::Debug;
let mut stack = UnsizedStack::<[i32]>::new();
stack.push([1, 2], |item| item as _);
stack.push([3, 4], |item| item as _);
stack.push([5, 6], |item| item as _);
dbg!(stack); // Print stack = [[1, 2], [3, 4], [5, 6]]
Dependencies
~58KB