[Media] Hashmap behaviour inside a loop due to lifetime issue

55 points dvishal-485
[Media] Hashmap behaviour inside a loop due to lifetime issue

Can someone explain this behaviour?
I don't understand why I can't use .remove(&(&str,&str)) while I can use .get(&(&str, &str)) without any error.

I cross-checked, they both accept the reference of the key. The only difference is .remove takes &mut self while .get takes &self.

My smart ass friend pointed out this has something to do with lifetime varience "Lifetimes in &mut T are invariant; Lifetimes in &T are covariant". But I still don't fully understand it.

What am I missing here?

Cargo version : 1.70.0