stack_collections-0.2.0 has been yanked.
stack_collections
Stack-allocated collections for Rust: fixed-capacity string and vector types that live entirely on the stack.
Features
StackString<N>: UTF-8 encoded, fixed-capacity string stored on the stackStackVec<T, CAP>: Fixed-capacity vector stored on the stackStackArrayString<N, CAP>: Convenience alias forStackVec<StackString<N>, CAP>- Zero heap allocations
const fnconstructors and many operations- Comprehensive API with safe and unsafe variants
- Full iterator support including
IntoIterator,DoubleEndedIterator, andExactSizeIterator - Standard trait implementations:
Debug,Display,Clone,Hash,PartialEq,Eq,Ord, etc. Writetrait implementation forStackString
Usage
Add this to your Cargo.toml:
[]
= "0.2.0"
StackString Example
use StackString;
StackVec Example
use StackVec;
StackArrayString Example
use StackArrayString;
When to Use
Use stack_collections when you:
- Need predictable memory usage without heap allocations
- Know the maximum capacity at compile time
- Want to avoid allocator overhead for small collections
- Are working in
no_stdenvironments (note: currently requiresstdfor some traits) - Need deterministic performance without allocator variance
API Overview
Both StackString and StackVec provide:
- Unchecked variants:
push_unchecked,pop_unchecked, etc. for performance-critical code - Try variants:
try_push,try_pop, etc. that returnOptioninstead of panicking - Standard methods:
push,pop,insert,remove,clear,truncate, etc. - Deref to slice/str: Seamless integration with standard library functions
Safety
This crate uses unsafe internally for performance but exposes a safe API. All unsafe operations are carefully documented and validated. The public API is designed to prevent
undefined behavior even when capacity is exceeded (operations will panic or return None instead).
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.