title: Cannot borrow immutable borrowed content as mutable
body: <p>I'm trying to develop a message routing app. I've read the official Rust docs and some articles and thought that I got how pointers, owning, and borrowing stuff works but realized that I didn't.</p>
  
  <pre><code>use std::collections::HashMap;
  use std::vec::Vec;
  
  struct Component {
      address: &amp;'static str,
      available_workers: i32,
      lang: i32
  }
  
  struct Components {
      data: HashMap&lt;i32, Vec&lt;Component&gt;&gt;
  }
  
  impl Components {
      fn new() -&gt; Components {
          Components {data: HashMap::new() }
      }
  
      fn addOrUpdate(&amp;mut self, component: Component) -&gt; &amp;Components {
          if !self.data.contains_key(&amp;component.lang) {
  
              self.data.insert(component.lang, vec![component]);
          } else {
              let mut q = self.data.get(&amp;component.lang); // this extra line is required because of the error: borrowed value does not live long enough
              let mut queue = q.as_mut().unwrap();
              queue.remove(0);
              queue.push(component);
          }
          self
      }
  
  }
  </code></pre>
  
  <p>(Also available on the <a href="https://play.rust-lang.org/?gist=8cd9bda8afba5dbb3d239214692302e0&amp;version=stable" rel="noreferrer">playground</a>)</p>
  
  <p>Produces the error: </p>
  
  <pre class="lang-none prettyprint-override"><code>error: cannot borrow immutable borrowed content `**queue` as mutable
    --&gt; src/main.rs:26:13
     |
  26 |             queue.remove(0);
     |             ^^^^^ cannot borrow as mutable
  
  error: cannot borrow immutable borrowed content `**queue` as mutable
    --&gt; src/main.rs:27:13
     |
  27 |             queue.push(component);
     |             ^^^^^ cannot borrow as mutable
  </code></pre>
  
  <p>Could you please explain the error and it would be great if you can give me the right implementation.</p>