[−][src]Crate tinyvec
tinyvec provides 100% safe vec-like data structures.
Provided Types
With no features enabled, this crate provides the ArrayVec type, which
is an array-backed storage. You can push values into the array and pop them
out of the array and so on. If the array is made to overflow it will panic.
Similarly, there is also a SliceVec type available, which is a vec-like
that's backed by a slice you provide. You can add and remove elements, but
if you overflow the slice it will panic.
With the alloc feature enabled, the crate also has a TinyVec type.
This is an enum type which is either an Inline(ArrayVec) or a Heap(Vec).
If a TinyVec is Inline and would overflow it automatically transitions
itself into being Heap mode instead of a panic.
All of this is done with no unsafe code within the crate. Technically the
Vec type from the standard library uses unsafe internally, but this
crate introduces no new unsafe code into your project.
The limitation is that the element type of a vec from this crate must
support the Default trait. This means that this crate isn't suitable for
all situations, but a very surprising number of types do support Default.
Other Features
grab_spare_slicelets you get access to the "inactive" portions of an ArrayVec.rustc_1_40makes the crate assume a minimum rust version of1.40.0, which allows some better internal optimizations.
API
The general goal of the crate is that, as much as possible, the vecs here
should be a "drop in" replacement for the standard library Vec type. We
strive to provide all of the Vec methods with the same names and
signatures. The exception is that the element type of some methods will have
a Default bound that's not part of the normal Vec type.
The vecs here also have a few additional methods that aren't on the Vec
type. In this case, the names tend to be fairly long so that they are
unlikely to clash with any future methods added to Vec.
Stability
- The
1.0series of the crate works with Rustc1.34.0or later, though you still need to have Rustc1.36.0to use theallocfeature. - The
2.0version of the crate is planned for some time after themin_const_genericsstuff becomes stable. This would greatly raise the minimum rust version and also allow us to totally eliminate the need for theArraytrait. The actual usage of the crate is not expected to break significantly in this transition.
Macros
| array_vec | Helper to make an |
| tiny_vec | feature="alloc"Helper to make a |
Structs
| ArrayVec | An array-backed, vector-like data structure. |
| ArrayVecDrain | Draining iterator for |
| ArrayVecIterator | Iterator for consuming an |
| ArrayVecSplice | Splicing iterator for |
| SliceVec | A slice-backed vector-like data structure. |
| SliceVecDrain | Draining iterator for |
| TinyVecSplice | Splicing iterator for |
Enums
| TinyVec | feature="alloc"A vector that starts inline, but can automatically move to the heap. |
| TinyVecDrain | Draining iterator for |
| TinyVecIterator | Iterator for consuming an |
Traits
| Array | A trait for types that are an array. |