title: Temporarily move out of borrowed content
body: <p>I'm tring to replace a value in a mutable borrow; moving part of it into the new value:</p>
  
  <pre><code>enum Foo&lt;T&gt; {
      Bar(T),
      Baz(T),
  }
  
  impl&lt;T&gt; Foo&lt;T&gt; {
      fn switch(&amp;mut self) {
          *self = match self {
              &amp;mut Foo::Bar(val) =&gt; Foo::Baz(val),
              &amp;mut Foo::Baz(val) =&gt; Foo::Bar(val),
          }
      }
  }
  </code></pre>
  
  <p>The code above doesn't work, and understandibly so, moving the value out of <code>self</code> breaks the integrity of it. But since that value is dropped immediately afterwards, I (if not the compiler) could guarantee it's safety.</p>
  
  <p>Is there some way to achieve this? I feel like this is a job for unsafe code, but I'm not sure how that would work.</p>