Hello. Could any one help me with one problem.
Person
use std::string::String;
pub struct Person {
pub name: String,
pub adult: bool,
pub children: Vec<Person>,
}
impl Default for Person {
fn default() -> Person {
Person {
name: String::default(),
adult: bool::default(),
children: vec![],
}
}
}
Example tree
let mut tree: Vec<Person> = vec![
Person {
name: "Grand parent".to_string(),
adult: true,
children: vec![
Person {
name: "Someone else's parent".to_string(),
adult: false,
children: vec![]
},
Person {
name: "Parent".to_string(),
adult: true,
children: vec![
Person {
name: "I want access this".to_string(),
adult: true,
children: vec![]
}
]
}
]
}
];
What I want is when I change any data of person in adults_list, it will automatically update inside tree.
Example
let mut adults_list: Vec<Person> = vec![tree[0].children[1].children[0]]; // THIS PART THAT I DON'T KNOW
adults_list[0].name = "SUCCESS";
// In tree it would look like this
let mut tree: Vec<Person> = vec![
Person {
name: "Grand parent",
adult: true,
children: vec![
Person {
name: "Someone else's parent",
adult: false,
children: vec![]
},
Person {
name: "Parent",
adult: true,
children: vec![
Person {
name: "SUCCESS",
adult: true,
children: vec![]
}
]
}
]
}
];