Currently all HashMap APIs which make insertion into a map possible (insert, entry) require the key by-value. If avoiding a clone is desired, the user must instead use something like if !map.contains(key) { map.insert(key.clone(), val); }, which results in key getting hashed twice.
Ideally, something like HashMap::insert_clone(key: &K, val: V) where K: Clone or HashMap::entry_clone(key: &K) where K: Clone would exist.
Currently all HashMap APIs which make insertion into a map possible (
insert,entry) require the key by-value. If avoiding acloneis desired, the user must instead use something likeif !map.contains(key) { map.insert(key.clone(), val); }, which results in key getting hashed twice.Ideally, something like
HashMap::insert_clone(key: &K, val: V) where K: CloneorHashMap::entry_clone(key: &K) where K: Clonewould exist.