How can I make a child struct have a reference to one of it's parents fields?
Example:
pub struct Parent<'a> {
s: String,
child: Child<'a>,
}
pub struct Child<'a> {
s: &'a String,
}
How do I get Child.s
to point to Parent.s
without triggering the borrow checker?
let s = String::new();
let child = Child {
s: &s
};
let parent = Parent {
child,
s,
};
This code triggers the following error since it's borrowed by child when trying to move to parent:
cannot move out of 's' because it is borrowed
Any pointers appreciated