Even better (for some cases) is to have that vector allocate in-place, in a SmallVec.
Edit: there is already a SmallSet that uses that (it keeps the keys unordered, so you can’t binary search them):
https://crates.io/crates/smallset
Since C++11 the situation is different, now people are using hash maps often enough (and even before that, Boost had hash maps. But not everybody likes and uses Boost).
Them being secure by default is kind of acceptable. But I still believe Rust standard library should offer a really easy way to use unsecure HashMaps/HashSets in a really simple, easy and succinct way. I think the current situation is not good enough, there’s space for improvements… In many situations I prefer faster hashes.
For HashSets it’s even better because there are no Values, so in that array there are less cache misses. In D language the threshold is about 40-100 integral keys, past that number a HashMap is faster… but there are many other considerations. Iterating on a vector is faster… So it depends on many factors.
Regarding HashMaps, I am still missing ergonomy of a hmap!{} macro to create HashMap literarls. I will wait for language improvements…