Suppose I have the following two structs:
struct Parent {
name: String,
}
impl Parent {
fn create_child(&self) -> Child {
Child { parent_name: &self.name }
}
}
struct Child<'a> {
parent_name: &'a str,
}
Now I'm attempting to create the following struct:
struct Everyone<'a> {
p: Parent,
c: Child<'a>,
}
However, the borrow checker won't allow me to do this:
fn main() {
let p = Parent { name: "foo".to_owned() };
let c = p.create_child();
let e = Everyone { p, c }; // error: p already borrowed!
}
How to properly write Everyone
struct?