Hi, I'm having a little trouble with a library I am working with.
The library has a struct that looks like this:
struct Foo;
impl Foo {
fn bar(mut self) -> Self {
// Does some stuff
}
}
I am using Foo
in a HashMap
and am trying to do the following:
let ref: &mut Foo = hash_map.get_mut(&key).unwrap();
ref = ref.bar();
This doesn't work as bar takes ownership of the Foo
instance. I have also tried doing std::mem::replace(ref, ref.bar())
, but this doesn't work as I "cannot move out of ref
because it is borrowed".
Is replacing ref
with ref.bar()
possible?