title: How can I update a value in a mutable HashMap?
body: <p>Here is what I am trying to do:</p>
  
  <pre><code>use std::collections::HashMap;
  
  fn main() {
      let mut my_map = HashMap::new();
      my_map.insert("a", 1);
      my_map.insert("b", 3);
  
      my_map["a"] += 10;
      // I expect my_map becomes {"b": 3, "a": 11}
  }
  </code></pre>
  
  <p>But this raises an error:</p>
  
  <p><strong>Rust 2015</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0594]: cannot assign to immutable indexed content
   --&gt; src/main.rs:8:5
    |
  8 |     my_map["a"] += 10;
    |     ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
    |
    = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `std::collections::HashMap&lt;&amp;str, i32&gt;`
  </code></pre>
  
  <p><strong>Rust 2018</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0594]: cannot assign to data in a `&amp;` reference
   --&gt; src/main.rs:8:5
    |
  8 |     my_map["a"] += 10;
    |     ^^^^^^^^^^^^^^^^^ cannot assign
  </code></pre>
  
  <p>I don't really understand what that means, since I made the <code>HashMap</code> mutable. When I try to update an element in a <code>vector</code>, I get the expected result:</p>
  
  <pre><code>let mut my_vec = vec![1, 2, 3];
  
  my_vec[0] += 10;
  println! {"{:?}", my_vec};
  // [11, 2, 3]
  </code></pre>
  
  <p>What is different about <code>HashMap</code> that I am getting the above error? Is there a way to update a value?</p>