The declaration of entry
is
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> // key is move into entry
whereas the one for get
is
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> where // k is just a shared reference
K: Borrow<Q>,
Q: Hash + Eq,
The Entry
interface contains key
and or_insert_with_key
, but both methods merely call for a reference to key
, so why does entry
need the ownership of key
while get
doesn't?
In other words, what functionality does Entry
offer by taking the ownership of key
? If all it offers can be achieved with a shared reference, then I would say requiring ownership is unnecessary.