I have the following code:
value: &'a str,
children: Option<Vec<Parent<'a>>>,
}
impl<'a> Parent<'a> {
pub fn new(value: &'a str, children: Option<Vec<Parent<'a>>>) -> Self {
Self { value, children }
}
pub fn add_child(&'a mut self, parent: Parent<'a>) {
self.children.as_mut().unwrap().push(parent);
}
}
And I can't figure out how to call add_child() twice without getting the error parent was mutably borrowed here in the previous iteration of the loop. When I use &'static it works, but I would like to know the proper way to fix this