I am hitting an issue with "function returning reference to local variables" that I'm having trouble resolving. Here is a simplified version of what I'm trying to do:
fn create_cat_then_populate_then_return_both<'a>() -> (Cat<'a>, Cat<'a>) {
let mut cat: Cat = Cat::new(None);
let cat2: Cat = cat.populate();
(cat, cat2)
}
struct Cat<'a> {
parent: Option<&'a Cat<'a>>,
has_children: bool,
}
impl<'a> Cat<'a> {
fn new(parent: Option<&'a Cat<'a>>) -> Cat<'a> {
Cat {
parent,
has_children: false,
}
}
fn populate(&mut self) -> Cat {
self.has_children = true;
Cat::new(Some(self))
}
}