Having something like this:
enum Bar {
Single,
Multi(Box<Bar>, Box<Bar>),
}
impl std::ops::AddAssign for Bar {
fn add_assign(&mut self, rhs: Bar) {
*self = Bar::Multi(Box::new(*self), Box::new(rhs)); // <- error E0507
// "workaround"
// let current = std::mem::replace(self, Bar::Single);
// *self = Bar::Multi(Box::new(current), Box::new(rhs));
}
}
fn main() {
let mut bar = Bar::Single;
bar += Bar::Single;
}
I currently have the workaround in my code, which does something similar. I tried to think how to do this with std::mem::replace()
or std::mem::take()
but couldn't figure it out.
So my question is, is possible to do something similar to the line that produces the error?