[−][src]Crate tinyvec
For all those times when you need just a little bit of vec support.
What This Is
This crate provides 100% safe code alternatives to both arrayvec and smallvec.
Being 100% safe means that you have to have some sort of compromise compared
to the versions using unsafe. In this case, the compromise is that the
element type must implement Default to be usable in these vecs. However,
that still allows you to use quite a few
types,
so I think that you'll find these vecs useful in many cases.
ArrayVecis an array-backed vec-like structure with a fixed capacity. If you try to grow the length past the array's capacity it will error or panic (depending on the method used).SliceVecis similar, but instead of the vec having an owned array, it holds onto a unique borrow of a slice. This means that it's far cheaper to pass around (since you don't move the whole array), but it can be trickier to thread a lifetime marker everywhere through all your function signatures.- (
allocfeature)TinyVecis an enum that's either an "Inline"ArrayVecor a "Heap"Vec. If it's Inline and you try to grow theArrayVecbeyond its array capacity it will quietly transition into Heap mode and then continue the operation.
Crate Goals
- The crate is 100% safe code. Not just a safe API, there are also no
unsafeinternals.#![forbid(unsafe_code)]. - No required dependencies.
- We might provide optional dependencies for extra functionality (eg:
serdecompatibility).
- We might provide optional dependencies for extra functionality (eg:
- The intended API is that, as much as possible, these types are
essentially a "drop-in" replacement for the standard
Vectype. Because of the "nounsafe" rule this can't be done perfectly.- Stable
Vecmethods that the vecs here also have should be the same general signature. - Unstable
Vecmethods are sometimes provided via a crate feature, but if so they also require a Nightly compiler. - Some methods are provided that are not part of the
Vectype, such as additional constructor methods. In this case, the names are rather long and whimsical in the hopes that they don't clash with any possible future methods ofVec. - If, in the future,
Vecstabilizes a method that clashes with an existing extra method here then we'll simply be forced to release a 2.y.z version. Not the end of the world. - Some methods of
Vecare simply inappropriate and will not be implemented here. For example, this crate cannot possibly implementfrom_raw_partsbecause it cannot callunsafemethods.
- Stable
Macros
| array_vec | Helper to make an |
| tiny_vec | Helper to make a |
Structs
| ArraySet | An array-backed set |
| ArrayVec | An array-backed, vector-like data structure. |
| ArrayVecDrain | Draining iterator for |
| ArrayVecIterator | Iterator for consuming an |
| InsertError | Error resulting from attempting to insert into a full array |
| Iter | Type returned by |
| SliceVec | A slice-backed vector-like data structure. |
| SliceVecDrain | Draining iterator for |
| TinyVecDrain | Draining iterator for |
Enums
| TinyVec | A vector that starts inline, but can automatically move to the heap. |
| TinyVecIterator | Iterator for consuming an |
Traits
| Array | A trait for types that are an array. |