Skip to main content

Module smallvec

Module smallvec 

Source
Expand description

A vector that stores elements inline up to a fixed capacity, then spills to the heap.

SmallVec<T, N> behaves like Vec<T> but keeps up to N elements on the stack. When more than N elements are needed, data is moved to a heap-allocated Vec<T>.

This is useful when the common case fits in a small, fixed buffer but you still need to handle occasional overflow without panicking.

§Examples

use planck_noalloc::smallvec::SmallVec;

let mut sv = SmallVec::<i32, 4>::new();
sv.push(1);
sv.push(2);
sv.push(3);
assert!(sv.is_inline());
assert_eq!(sv.as_slice(), &[1, 2, 3]);

// Push beyond inline capacity — spills to heap
sv.push(4);
sv.push(5);
assert!(!sv.is_inline());
assert_eq!(sv.as_slice(), &[1, 2, 3, 4, 5]);

Structs§

SmallVec
A vector that stores up to N elements inline on the stack, spilling to the heap when capacity is exceeded.
SmallVecIntoIter
Owning iterator over a SmallVec.