So I have this code
Which is this
pub struct Tree {
pub left: Option<Box<Tree>>,
pub right: Option<Box<Tree>>,
handle: u64,
}
impl Tree {
pub fn remove_from_tree(&mut self, handle: u64) -> bool {
// looks in some data in self to determine if it should be deleted
// or not, then returns true to tell the parent to delete it
if self.handle == handle {
return true;
}
if let Some(ref mut split) = self.left {
if Self::remove_from_tree(split, handle) {
self.left = None;
}
}
if let Some(ref mut split) = self.right {
if Self::remove_from_tree(split, handle) {
self.right = None;
}
}
false
}
}
And I get this error
<anon>:18:17: 18:33 error: cannot assign to `self.left` because it is borrowed [E0506]
<anon>:18 self.left = None;
^~~~~~~~~~~~~~~~
<anon>:16:21: 16:34 note: borrow of `self.left` occurs here
<anon>:16 if let Some(ref mut split) = self.left {
^~~~~~~~~~~~~
I can likely do some (bad) workaround to get around this but I'm wonder if anyone has some suggestion how in general to deal with this case?
Cheers!