if let Some(v) = map.get_mut(&key){
*v = 5;
} else {
map.insert(key, 5);
}
map is mutably borrowed also for the else clause, but I have lost any reference to what I borrowed, so in the else block it is false that map is borrowed as mutable more that once as the compiler complains.
Ah ok. Yeah, HashMap has a nice API to work around this issue for cases like this. Similar workarounds can be used for other cases (the linked blog shows a few, and explains the general problem).