title: How to access value in RefCell properly
body: <p>I'm trying to wrap my head around <code>Rc</code> and <code>RefCell</code> in Rust. What I'm trying to achieve is to to have multiple mutable references to the same objects.</p>
  
  <p>I came up with this dummy code:</p>
  
  <pre><code>use std::rc::Rc;
  use std::cell::RefCell;
  
  struct Person {
      name: String,
      mother: Option&lt;Rc&lt;RefCell&lt;Person&gt;&gt;&gt;,
      father: Option&lt;Rc&lt;RefCell&lt;Person&gt;&gt;&gt;,
      partner: Option&lt;Rc&lt;RefCell&lt;Person&gt;&gt;&gt;
  }
  
  pub fn main () {
  
      let mut susan = Person {
          name: "Susan".to_string(),
          mother: None,
          father: None,
          partner: None
      };
  
      let mut boxed_susan = Rc::new(RefCell::new(susan));
  
      let mut john = Person {
          name: "John".to_string(),
          mother: None,
          father: None,
          partner: Some(boxed_susan.clone())
      };
  
      let mut boxed_john = Rc::new(RefCell::new(john));
  
      let mut fred = Person {
          name: "Fred".to_string(),
          mother: Some(boxed_susan.clone()),
          father: Some(boxed_john.clone()),
          partner: None
      };
  
      fred.mother.unwrap().borrow_mut().name = "Susana".to_string();
  
      println!("{}", boxed_susan.borrow().name);
  
      // boxed_john.borrow().partner.unwrap().borrow_mut().name = "Susanna".to_string();
      // println!("{}", boxed_susan.borrow().name);
  
  }
  </code></pre>
  
  <p>The most interesting part is this:</p>
  
  <pre><code>    fred.mother.unwrap().borrow_mut().name = "Susana".to_string();
      println!("{}", boxed_susan.borrow().name)
  </code></pre>
  
  <p>I change the name of Freds mother and then print out the name of Susan which should happen to be exactly the same reference. And surprise, surprise it prints out "Susana" so I am assuming that my little experiment of having shared mutable references was successful. </p>
  
  <p>However, now I wanted to mutate it again this time accessing it as the partner of John which should also happen to be exactly the same instance.</p>
  
  <p>Unfortunately when I comment in the following two lines:</p>
  
  <pre><code>// boxed_john.borrow().partner.unwrap().borrow_mut().name = "Susanna".to_string();
  // println!("{}", boxed_susan.borrow().name);
  </code></pre>
  
  <p>I'm running into my old friend <code>cannot move out of dereference of</code>&amp;<code>-pointer</code>. What am I doing wrong here?</p>