Expand description
Fixed-capacity vector implementation backed by a stack-allocated array.
This module provides ArrayVec, a vector-like data structure with a compile-time
fixed capacity. Unlike Vec from the standard library, ArrayVec stores its elements
inline in a fixed-size array on the stack, avoiding heap allocation entirely.
§Features
- Zero heap allocations
- Compile-time fixed capacity
- API similar to standard
Vec - Works in
no_stdenvironments - Safe handling of uninitialized memory
§Capacity Management
The capacity is specified as a const generic parameter and cannot be changed at runtime.
Attempting to push beyond capacity will either return an error (ArrayVec::try_push)
or panic (ArrayVec::push).
§Performance
- Push/pop operations: O(1)
- Indexing: O(1)
- Better cache locality than heap-allocated vectors
- No allocator overhead
§Examples
use planck_noalloc::vec::ArrayVec;
let mut vec = ArrayVec::<i32, 10>::new();
// Push elements
vec.push(1);
vec.push(2);
vec.push(3);
// Access elements
assert_eq!(vec[0], 1);
assert_eq!(vec.len(), 3);
// Iterate
for value in vec.iter() {
println!("{}", value);
}
// Get as slice
let slice = vec.as_slice();
assert_eq!(slice, &[1, 2, 3]);Structs§
- Array
Vec - A fixed-size array, which has vector-like operations.
Enums§
- Array
VecError - Errors that can occur when operating on an
ArrayVec.