title: items from traits can only be used if the trait is implemented and in scope
body: <p>I tried to implement the Observer pattern from <em>Heads-up Design Patterns</em>, which was originally written in Java:</p>
  
  <pre><code>use std::cell::RefCell;
  use std::rc::Rc;
  use std::borrow::BorrowMut;
  
  trait Subject {
      fn registerObserver(&amp;mut self, observer: Rc&lt;RefCell&lt;Observer&gt;&gt;);
      fn removeObserver(&amp;mut self, observer: Rc&lt;RefCell&lt;Observer&gt;&gt;);
      fn notifyObserver(&amp;self, observer: Rc&lt;RefCell&lt;Observer&gt;&gt;);
  }
  
  trait Observer {
      fn update(&amp;mut self, data: f32);
  }
  
  
  struct Teacher {
      observers: Vec&lt;Rc&lt;RefCell&lt;Observer&gt;&gt;&gt;,
      data: f32,
  }
  impl Teacher {
      pub fn print(&amp;self) {
          println!("teacher = {:}", self.data);
      }
  }
  impl Subject for Teacher {
      fn registerObserver(&amp;mut self, observer: Rc&lt;RefCell&lt;Observer&gt;&gt;) {
          self.observers.push(observer);
      }
      fn removeObserver(&amp;mut self, observer: Rc&lt;RefCell&lt;Observer&gt;&gt;) {
          println!("Teacher.removeObserver(...) not implemented yet...")
      }
      fn notifyObserver(&amp;self, observer: Rc&lt;RefCell&lt;Observer&gt;&gt;) {
          for observer in self.observers {
              let mut loc_obs = observer.borrow_mut();
              loc_obs.update(self.data);
          }
      }
  }
  
  struct Student {
      data: f32,
  }
  impl Student {
      pub fn print(&amp;self) {
          println!("student = {:}", self.data);
      }
  }
  impl Observer for Student {
      fn update(&amp;mut self, data: f32) {
          self.data = data;
      }
  }
  
  
  
  fn main() {
      let mut teacher = Teacher {
          observers: Vec::new(),
          data: 42.,
      };
      teacher.print();
  }
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?gist=dd58495d60abf192d34f146dd7954507&amp;version=undefined" rel="noreferrer">Playground</a></p>
  
  <p>The compiler tells me </p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0599]: no method named `update` found for type `&amp;mut std::rc::Rc&lt;std::cell::RefCell&lt;Observer + 'static&gt;&gt;` in the current scope
    --&gt; src/main.rs:35:21
     |
  35 |             loc_obs.update(self.data);
     |                     ^^^^^^
     |
     = help: items from traits can only be used if the trait is implemented and in scope
     = note: the following trait defines an item `update`, perhaps you need to implement it:
             candidate #1: `Observer`
  </code></pre>
  
  <p>Where is my error?</p>