Expand description
ValueVec<T>: a by-value, ref-less vector with interior mutability.
You can convert to and from a Vec<T> at zero cost.
Key properties:
- All mutating operations use
&self(immutable receiver). - No references to elements are ever given out.
- Elements are inserted/removed/moved by value.
- Getting a value returns a
Clone(orCopy) of the stored element. - Many shared immutable references to a
ValueVeccan exist simultaneously safely.
Trade-offs:
- You can’t borrow into the backing memory; you pay cloning cost to read.
- In return, the backing storage may reallocate at will without invalidating any external references (because none are ever issued).
Functionality:
For any functionality of Vec<T> that ValueVec<T> doesn’t provide,
you can use into_vec to convert to a Vec<T> at zero cost.
Soundness:
We require T to be Copy to avoid subtle soundness issues. However, this requirement
could be replaced with a requirement that prevents re-entrance into methods of
ValueVec<T> (directly or indirectly) from the Drop or Clone implementations of T.
Structs§
- Value
Vec - A by-value,
ref-less vector with interior mutability. Values of typeVcan be moved into and out of the vector. We requireVto beCopyto avoid subtle soundness issues.