Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
use std::rc::Rc;
struct N {
id: i32,
edges: Vec<Rc<N>>
pub fn main() {
let mut x = Rc::new( N { id: 1, edges: vec!() });
let mut y = Rc::new( N { id: 2, edges: vec!() });
// borrow the contents of x temporarily for mutating its edges.
let mut n: &mut N = Rc::get_mut(&mut x).unwrap();
n.edges.push(y.clone()); // incr y's ref count.
let mut n: &mut N = Rc::get_mut(&mut y).unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment