title: Swap two elements in a vector in rust
body: <p>I want to swap two elements in a vector.<br />
  I wrote this function to swap elements, but it gives it gives an error.</p>
  <pre class="lang-rust prettyprint-override"><code>fn swap&lt;T&gt;(arr: &amp;mut Vec&lt;T&gt;, i: usize, j: usize) {
      let temp = arr[i];
      arr[i] = arr[j];
      arr[j] = temp;
  }
  </code></pre>
  <pre><code>error[E0507]: cannot move out of index of `Vec&lt;T&gt;`
   --&gt; src/quick_sort.rs:2:16
    |
  2 |     let temp = arr[i];
    |                ^^^^^^
    |                |
    |                move occurs because value has type `T`, which does not implement the `Copy` trait
    |                help: consider borrowing here: `&amp;arr[i]`
  </code></pre>