Iterating through a recursive structure using mutable references and returning the last valid reference
问题 I'm trying to recurse down a structure of nodes, modifying them, and then returning the last Node that I get to. I solved the problems with mutable references in the loop using an example in the non-lexical lifetimes RFC. If I try to return the mutable reference to the last Node , I get a use of moved value error: #[derive(Debug)] struct Node { children: Vec<Node>, } impl Node { fn new(children: Vec<Self>) -> Self { Self { children } } fn get_last(&mut self) -> Option<&mut Node> { self