title: How can I swap items in a vector, slice, or array in Rust?
body: <p>My code looks like this:</p>
  
  <pre><code>fn swap&lt;T&gt;(mut collection: Vec&lt;T&gt;, a: usize, b: usize) {
      let temp = collection[a];
      collection[a] = collection[b];
      collection[b] = temp;
  }
  </code></pre>
  
  <p>Rust is pretty sure I'm not allowed to "move out of dereference" or "move out of indexed content", whatever that is. How do I convince Rust that this is possible?</p>