You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::rc::Rc;// All Parent state that needs to be shared with Child goes herestructData{name:String}structParent{children:Vec<Child>,data:Rc<Data>,}structChild{parent:Rc<Data>,// or Weak<Inner> if that's desirabledata:Rc<Data>,}fnmain(){let data = Rc::new(Data{name:"parent".into()});letmut parent = Parent{children:Vec::new(), data};let child = Child{parent:Rc::clone(&parent.data),data:Rc::new(Data{name:"child1".into()})};
parent.children.push(child);for child in parent.children.iter(){println!("child: {}, parent: {}", child.data.name, child.parent.name);}}
The text was updated successfully, but these errors were encountered:
1. A raw ptr version:
2. A Rc version:
The text was updated successfully, but these errors were encountered: