Expand description
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:
- Enable safe const construction of stack collections.
- 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:
ⓘ
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
.
Modules§
- litemap 🔒
Structs§
- A boxed slice that supports no-allocation, constant values if length 0 or 1.
- An iterator that yields elements from a
ShortBoxSlice
.
Enums§
- A boxed slice that supports no-allocation, constant values if length 0 or 1. Using ZeroOne(Option
) saves 8 bytes in ShortBoxSlice via niche optimization.