title: How to change value in a BTreeMap container
body: <p>Code:</p>
  
  <pre><code>#[derive(Debug)]
  struct Haha {
      data: i32,
  }
  
  use std::collections::BTreeMap;
  
  fn main() {
      let mut map: BTreeMap&lt;i8, Option&lt;Box&lt;Haha&gt;&gt;&gt; = BTreeMap::new();
      map.insert(1, Some(Box::new(Haha { data: 3 })));
      map.insert(2, None);
  
      for (key, value) in map.iter_mut() {
          if value.is_none() {        // if find `None`, change it to a `Some(Haha)`
              value = Some(Box::new(Haha { data: 5 }));
          }
      }
  }
  </code></pre>
  
  <p>I want to make a function that when I get the value <code>None</code> in <code>BTreeMap.value</code>, I change it to <code>Some</code> value, not a reference. But it comes out a mistake:</p>
  
  <pre class="lang-none prettyprint-override"><code> error[E0308]: mismatched types
    --&gt; Untitled.rs:15:12
     |
  15 |            value = Some(Box::new(Haha{data: 5}));
     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected mutable reference, found enum `std::option::Option`
     |
     = note: expected type `&amp;mut std::option::Option&lt;std::boxed::Box&lt;Haha&gt;&gt;`
                found type `std::option::Option&lt;std::boxed::Box&lt;Haha&gt;&gt;`
     = help: here are some functions which might fulfill your needs:
             - .unwrap()
  </code></pre>
  
  <p>Because using <code>map.iter_mut()</code> I can only get the reference. How to send the true value <code>Some(Haha)</code> but not a reference to the mut reference <code>value</code>? If I change to <code>value = &amp; mut Some(Box::new(Haha { data: 5 }));</code> Because <code>Some(Box...)</code> will be destructed, so it will come out another mistake. </p>