Can I use `core::mem::replace` to replace value `get_mut()` from a `HashMap`?

Is core::mem::replace(map.get_mut(&key), src) same as map.entry(key).and_modify(move |dest| core::mem::replace(dest, src))?

map.get_mut(&key) returns an Option, so the first snippet of code doesn't compile.

ignore it, just thinking about the &mut T in it.

Yes, of course. A &mut T is a &mut T, regardless of where you got it from.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.