MiniVec

Type Alias MiniVec 

Source
pub type MiniVec<T> = AutoVec<T, 8>;
Expand description

A small AutoVec with a stack capacity of 8 elements.

This is an alias for AutoVec<T, 8>.

MiniVec is optimized for scenarios where you expect small collections most of the time, typically 8 or fewer elements. It provides zero-cost stack allocation for small data and automatically spills to the heap when capacity is exceeded.

§Examples

let mut vec: MiniVec<i32> = MiniVec::new();

// Small collections stay on the stack with no heap allocation
vec.push(1);
vec.push(2);
vec.push(3);
assert!(vec.in_stack());
assert_eq!(vec, [1, 2, 3]);

// Exceeding capacity automatically moves to heap
vec.extend(&[4, 5, 6, 7, 8, 9]);
assert!(!vec.in_stack());
assert_eq!(vec.len(), 9);

Aliased Type§

pub struct MiniVec<T>(/* private fields */);