title: How do I create two new mutable slices from one slice?
body: <p>I would like to take a mutable slice and copy the contents into two new mutable slices. Each slice being one half of the original.</p>
  
  <p>My attempt #1:</p>
  
  <pre><code>let my_list: &amp;mut [u8] = &amp;mut [0, 1, 2, 3, 4, 5];
  let list_a: &amp;mut [u8] = my_list[0..3].clone();
  let list_b: &amp;mut [u8] = my_list[3..6].clone();
  println!("{:?}", my_list);
  println!("{:?}", list_a);
  println!("{:?}", list_b);
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: no method named `clone` found for type `[u8]` in the current scope
   --&gt; src/main.rs:3:43
    |
  3 |     let list_a: &amp;mut [u8] = my_list[0..3].clone();
    |                                           ^^^^^
  
  error: no method named `clone` found for type `[u8]` in the current scope
   --&gt; src/main.rs:4:43
    |
  4 |     let list_b: &amp;mut [u8] = my_list[3..6].clone();
    |                                           ^^^^^
  </code></pre>
  
  <p>My attempt #2:</p>
  
  <pre><code>let my_list: &amp;mut [u8] = &amp;mut [0, 1, 2, 3, 4, 5];
  let list_a: &amp;mut [u8] = my_list[0..3].to_owned();
  let list_b: &amp;mut [u8] = my_list[3..6].to_owned();
  println!("{:?}", my_list);
  println!("{:?}", list_a);
  println!("{:?}", list_b);
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
    --&gt; src/main.rs:12:29
     |
  12 |     let list_a: &amp;mut [u8] = my_list[0..3].to_owned();
     |                             ^^^^^^^^^^^^^^^^^^^^^^^^ expected &amp;mut [u8], found struct `std::vec::Vec`
     |
     = note: expected type `&amp;mut [u8]`
                found type `std::vec::Vec&lt;u8&gt;`
     = help: try with `&amp;mut my_list[0..3].to_owned()`
  
  error[E0308]: mismatched types
    --&gt; src/main.rs:13:29
     |
  13 |     let list_b: &amp;mut [u8] = my_list[3..6].to_owned();
     |                             ^^^^^^^^^^^^^^^^^^^^^^^^ expected &amp;mut [u8], found struct `std::vec::Vec`
     |
     = note: expected type `&amp;mut [u8]`
                found type `std::vec::Vec&lt;u8&gt;`
     = help: try with `&amp;mut my_list[3..6].to_owned()`
  </code></pre>
  
  <p>I can use two <code>Vec&lt;u8&gt;</code> and just loop over the input and push cloned values I guess, but I was hoping there was a nicer way to do this:</p>
  
  <pre><code>extern crate rand;
  
  use rand::{thread_rng, Rng};
  
  fn main() {
      let my_list: &amp;mut [u8] = &amp;mut [0; 100];
      thread_rng().fill_bytes(my_list);
      let list_a = &amp;mut Vec::new();
      let list_b = &amp;mut Vec::new();
      for i in 0..my_list.len() {
          if i &lt; my_list.len() / 2 {
              list_a.push(my_list[i].clone());
          } else {
              list_b.push(my_list[i].clone());
          }
      }
      println!("{:?}", list_a.as_slice());
      println!("{:?}", list_b.as_slice());
      println!("{:?}", my_list);
  }
  </code></pre>