collect() Reuses Your Allocation: Rust's In-Place Collection
Rust’s in-place collect reuses the source Vec’s allocation when the iterator and element sizes allow it, turning map+collect into a loop with no allocation.
Rust’s in-place collect reuses the source Vec’s allocation when the iterator and element sizes allow it, turning map+collect into a loop with no allocation.
Rust’s RawVec keeps its capacity in a niche-typed UsizeNoHighBit, making Vec three words, with a growth policy of max(2*cap, required) and a tiny-vector minimum of 8 bytes for u8.