Expand description
A space-optimized version of alloc::vec::Vec
that’s only the size of a single pointer!
Ideal for low-level APIs where ABI calling conventions will typically require most structs be
spilled onto the stack and copied instead of being passed solely in registers.
For example, in the x64 msvc ABI:
There’s a strict one-to-one correspondence between a function call’s arguments and the registers used for those arguments. Any argument that doesn’t fit in 8 bytes, or isn’t 1, 2, 4, or 8 bytes, must be passed by reference. A single argument is never spread across multiple registers.
In addition, its single word size makes it ideal for use as a struct member where multiple
inclusions of Vec
as a field can balloon the size.
In general, MiniVec
aims to be API compatible with what’s currently stable in the stdlib so some
Nightly features are not supported.
MiniVec
has stable implementations of the following nightly-only associated functions on Vec
:
MiniVec
has the following associated functions not found in Vec
:
MiniVec
has the following extensions to the existing Vec
API:
push
returns a mutable reference to the newly created element
MiniVec
is #![no_std]
-compliant.
MiniVec
does not support zero-sized types.
Eventual TODO’s:
- add myriad specializations to associated functions such as
FromIterator
once stable - add Allocator support once stable
- Because
MiniVec
is only a single pointer,MiniVec::new_in()
will be forced to allocate when using a statefulAllocator
. A theoretical implementation ofMiniVec
might be able to avoid an allocation here in the case of a custom zero-sizedAllocator
but that has not been implemented.
- Because
Macros§
- mini_
vec mini_vec!
is a macro similar in spirit to the stdlib’svec!
.
Structs§
- Drain
Drain
is an iterator that removes the selected sub-range from theMiniVec
and returns the removed elements to the caller lazily.- Drain
Filter DrainFilter
is a version ofDrain
that uses the supplied predicate to determine when an element should be removed from theMiniVec
and returned to the user.- Into
Iter IntoIter
is an iterator type that consumes theMiniVec
and transfers ownership of the contained elements to the caller when iterated.- MiniVec
MiniVec
is a space-optimized implementation ofalloc::vec::Vec
that is only the size of a single pointer and also extends portions of its API.MiniVec
also aims to bring as many Nightly features fromVec
to stable toolchains as is possible. In many cases, it is a drop-in replacement forVec
.- Splice
Splice
is an iterator that removes a sub-section of the backingMiniVec
and then replaces it with the contents of another iterator. The removed sub-section and the iterator used to replace it can have independent lengths.- TryReserve
Error TryReserveError
is the error type returned from thetry_reserve
family of functions.
Enums§
- Layout
Err LayoutErr
is the error type returned by the alignment-based associated functions forMiniVec
- TryReserve
Error Kind TryReserveErrorKind
is a variant encompassing the various types of allocation failures that can occur.