unsized-vec-0.0.1-alpha.2 has been yanked.
unsized-vec
UnsizedVec<T> is like Vec<T>, but T can be ?Sized.
Features
- Similar API to
Vec. - Same time complexity as
Vecfor indexing, push, pop, insert, remove (more or less)- Exception: when
T's alignment isn't fixed at compile-time, adding a new element to theVecwith a greater alignment than all elements currently present will take $\mathcal{O}(n)$ time, and will most likely reallocate.
- Exception: when
- For
T: Sized, only one heap allocation, approximately same memory layout asVec. - For unsized
T, two heap allocations (one for the elements, one for the pointer metadata). #[no_std](but requiresalloc).- Experimental, nightly-only.
Example
use Debug;
use ;
// `Box::new()` necessary only to coerce the values to trait objects.
let obj: = Boxnew;
let obj_2: = Boxnew;
let mut vec: = unsized_vec!;
for traitobj in &vec ;
assert_eq!;
let popped = box_new_with;
dbg!;
assert_eq!;