one of the most common patterns with hashmaps is "insert if no matching key". there are many ways to do this, get/insert, try_insert, entry+or_default, but all of them have one of two problems:
- they require searching the hashmap twice
- they require giving the hashmap an owned instance of the key, even if no entry is being constructed
so you're always stuck choosing your favorite flavor of inefficiency, extra allocations, or extra searches.
unfortunatly, there's not a ton of ways to handle this in safe code, but i can think of at least one that works decently for the case of a String or Vec that is reused as a buffer (eg. for read_line).
the method could take an owned key, and then either return a VacantEntry, or return the key you gave it, transferring the ownership back to you and letting you use that heap allocation for something else.
a more general api would take an borrowed key, then conditionally return some sort of KeylessVacantEntry, which would then take an owned key and value. unfortunatly this could cause hashmap corruption if the borrowed and owned keys are not actually identical.
perhaps something like this could be built using the nightly hash_raw_entry feature, or perhaps it has already been built, or perhaps i'm missing something.