Could collections hypothetically store keys and values inline?
Rust Internals [Unofficial]
April 30, 2026
Oh interesting, though I do think this is a somewhat different thing.
This is not a “small map optimization” where if there are few enough key-value pairs, they get stored in the pointers and other stuff you need on the stack anyway (which is what compact_str in Rust and “small string optimizations” in C++ do); rather, it specifically reserves space for some number of key-value pairs on the stack.
Reserving space on the stack is a different data type which you’re not precluded from creating by guaranteeing that when you don’t allocate that space everything will be stored on the heap,
Discussion in the ATmosphere