[−][src]Crate tinyvec
Programmers can have a little vec, as a treat.
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).- (
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.- 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,ArrayVeccannot possibly implementfrom_raw_parts.
- Stable
Macros
| array_vec | Helper to make an |
| tiny_vec | Helper to make a |
Structs
| ArrayVec | An array-backed, vector-like data structure. |
| ArrayVecDrain | Draining iterator for |
| ArrayVecIterator | Iterator for consuming an |
| 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. |