mod.rs |
This module includes variable-length data types that are const-constructible for single
values and overflow to the heap.
# Why?
This module is far from the first stack-or-heap vector in the Rust ecosystem. It was created
with the following value proposition:
1. Enable safe const construction of stack collections.
2. Avoid stack size penalties common with stack-or-heap collections.
As of this writing, `heapless` and `tinyvec` don't support const construction except
for empty vectors, and `smallvec` supports it on unstable.
Additionally, [`ShortBoxSlice`] has a smaller stack size than any of these:
```ignore
use core::mem::size_of;
// NonZeroU64 has a niche that this module utilizes
use core::num::NonZeroU64;
// ShortBoxSlice is the same size as `Box<[]>` for small or nichey values
assert_eq!(16, size_of::<shortvec::ShortBoxSlice::<NonZeroU64>>());
// Note: SmallVec supports pushing and therefore has a capacity field
assert_eq!(24, size_of::<smallvec::SmallVec::<[NonZeroU64; 1]>>());
// Note: heapless doesn't support spilling to the heap
assert_eq!(16, size_of::<heapless::Vec::<NonZeroU64, 1>>());
// Note: TinyVec only supports types that implement `Default`
assert_eq!(24, size_of::<tinyvec::TinyVec::<[u64; 1]>>());
```
The module is `no_std` with `alloc`. |
10813 |