An indirection-collapsing container that generalizes nested.
FlatVec can be used like a
Vec<Vec<u8>>, but with a maximum of 2 heap
allocations instead of n + 1 (currently it’s always 2 but that should change with 1.51).
Insertion into and retrieval from a
FlatVec is mediated by two traits,
FromFlat, which are both parameterized on two types. The simplest way to use this crate is to
impl IntoFlat<T, u8> for T and
impl FromFlat<'_, T, u8> for T for some type
T in your crate.
But since the interface supports a generic backing type parameter, the flattened input objects
can be stored as any representation that is convenient.
u8 is a reasonable default choice,
but may not be quite right for your application.
FromFlat has a lifetime parameter, accessing the stored objects in a
FlatVec can be a zero-copy operation. For example, one may flatten objects with indirections
into a dense in-memory storage, then access them later via a reference-wrapping handle type.
A simple example of this is in
This interface is extremely powerful and essentially amounts to in-memory serialization and
conversion all in one. For example, a user can construct a
FlatVec that compresses all of its
elements with gzip. This is not necessarily a good idea, but you can do it.
An indirection-collapsing container with minimal allocation
A wrapper over the innards of a
FlatVec which exposes mutating operations which cannot
corrupt other elements when inserting a new element.
FromFlat<'a, Flattened> for Dest to get a
Dest from a
IntoFlat<Flattened> for Source to insert a
Source into a