{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreidb5ad6zj5lnw4kj6gzwuoyanvdq2vntlqj2fwlfsnuq4vqqb3xqu",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mkpdqqjzhze2"
},
"path": "/t/could-collections-hypothetically-store-keys-and-values-inline/24195#post_14",
"publishedAt": "2026-04-30T08:52:03.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "Speed aside, you can't create a `&Vec` or `&mut Vec` without literally having a valid `Vec` in memory and if you have a valid `Vec` in memory then which frees the allocation when dropped and you need to do `CompactVec::into()` and then `CompactVec::from()`—which requires ownership and so requires ugly swapping if you're, for example, working with an array of `CompactVec`s.\n\nFor example, what would have been `array_of_arrays[i].push(foo)` becomes\n\n\n {\n let mut temp: Vec<_> = std::mem::take(&mut array_of_arrays[i]).into();\n temp.push(foo);\n array_of_arrays[i] = temp.into();\n }\n\n\nand similarly at every other place of usage. The ergonomics of that are sufficiently bad that I don't think anyone is going to do this outside of situations with very strict memory constraints.",
"title": "Could collections hypothetically store keys and values inline?"
}