cap_vec
A heap-allocated, fixed-capacity, variable-size array, no_std compatible.
CapVec<T, N> provides a middle ground between stack-allocated arrays [T; N] and dynamically growing vectors Vec<T>.
It allocates a heap-backed buffer of fixed capacity N, but allows the logical length to grow or shrink dynamically, up to that capacity.
✨ Features
- ✅ Fixed capacity — set at compile time.
- ✅ Heap allocation — no stack overflow even for large
N. - ✅ no_std compatible — uses only
alloc. - ✅ Supports most common collection operations:
push,pop,insert,removeclear,extend,drainiter,iter_mut, andinto_iter
- ✅ Safe, ergonomic API — mirrors
Vec<T>where possible. - ✅ Zero-cost iteration (implements
Iterator,DoubleEndedIterator,FusedIterator). - ✅ No hidden allocations after initialization.
🚀 Example
use CapVec;
🔨 Installation
Add cap_vec to your Cargo.toml:
or edit your Cargo.toml manually by adding:
[]
= "0.2"
Safety and Coverage
This crate contains a small portion of unsafe code.
All tests run under miri and the tests cover about 80% of the code.
You can generate the coverage report using tarpaulin.
Contributions
Contributions are always welcome! Feel free to open an issue or submit a pull request.
License
This crate is licensed under the MIT License. See LICENSE for more details.