3 ms·
For example, by explicitly calling shrink_to_fit. So you either have fragmentation, or an extra copy if you're not careful, but none of the solutions let you fo
by cmrx64 3y ago
For example, by explicitly calling shrink_to_fit. So you either have fragmentation, or an extra copy if you're not careful, but none of the solutions let you forget about the detail entirely.
- invpt 3y agoIf you look at the source for into_boxed_slice, it calls shrink_to_fit at the beginning before doing anything else. Hence the documentation is slightly wrong, and no copies occur. Edit: I submitted a PR to clear up the docs: https://github.com/rust-lang/rust/pull/120110 https://github.com/rust-lang/rust/pull/120110
- cmrx64 3y agothank you!
- sapiogram 3y agoOr alternatively, the vector was created with `Vec::with_capacity()` or `ExactSizeIterator::collect()`, and had the correct capacity all along.