I am coding a small program where I traverse a tree structure using a visitor. During the visit I want to store a reference to some node in my visitor struct.
My code currently looks like this :
However the lifetime checker is screaming and I can't get it to work. Is it possible to do it using somehow explicit lifetimes ?
error[E0312]: lifetime of reference outlives lifetime of borrowed content...
--> src\main.rs:12:28
|
12 | self.saved_node= node;
| ^^^^^
|
= note: ...the reference is valid for the static lifetime...
note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the method body at 11:5
--> src\main.rs:11:5
|
11 | / fn visit(&mut self, node: &Node) {
12 | | self.saved_node = node;
13 | | }
| |_____^