Why does HashMap.entry take a K?


HashMap.entry takes a K:
fn entry(&mut self, key: K) -> Entry<K, V>
Whereas many other HashMap accessors such as get, contains_key, etc, take:
fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> where K: Borrow<Q>, Q: Hash + Eq
If you use entry, and the map happenned to already contain that key, and you need to use the same key again later, now you’ve made a useless copy. IMO, better would be:
fn entry<Q: ?Sized>(&mut self, k: &Q) -> Entry<K, V> where K: Borrow<Q>, for<'q> &'q Q: Into<K>, Q: Hash + Eq


Everything is explained here: https://internals.rust-lang.org/t/head-desking-on-entry-api-4-0/2156