(2e71828 already gave the answer here, but to explore this a bit more.)
Note that this is a good time to think about the type in use and ponder whether it's what you actually meant. For example, what can you do with a &mut Option<...>
? Is that what you wanted people to do for this case?
In particular, if get
returns me a &mut Option<...>
, that means I can write a Some(...)
into it. But it doesn't really make sense to write anywhere if the lookup failed, so that's probably not the type you wanted. (And this logic is indepedent of the fact that you got a borrowck error.)
And if you're in general unsure where to go, following what std
does can often help: [T]::get_mut
returns an Option<&mut ...>
, not a &mut Option<...>
.