pub struct AbstractSyntaxTree {
buffer: Rc<RefCell<Vec<RefCell<Expression>>>>,
root: ExpressionIndex,
}
impl AbstractSyntaxTree {
fn try_get_mut_expression_by_location(
&mut self,
location: ExpressionIndex,
) -> Option<RefMut<'_, Expression>> {
Some(self.buffer.borrow_mut().get_mut(location)?.borrow_mut())
}
}
The above code fails to compile with cannot return value referencing temporary value
-
Is this really a temporary value? Shouldn't this reference be valid as long as the AbstractSyntaxTree struct exists?
-
Would you implement this tree a different way?