title: How to idiomatically copy a slice?
body: <p>In Go, copying slices is standard-fare and looks like this:</p>
  
  <pre class="lang-golang prettyprint-override"><code># It will figure out the details to match slice sizes
  dst = copy(dst[n:], src[:m])
  </code></pre>
  
  <p>In Rust, I couldn't find a similar method as replacement. Something I came up with looks like this:</p>
  
  <pre><code>fn copy_slice(dst: &amp;mut [u8], src: &amp;[u8]) -&gt; usize {
      let mut c = 0;
      for (&amp;mut d, &amp;s) in dst.iter_mut().zip(src.iter()) {
          d = s;
          c += 1;
      }
      c
  }
  </code></pre>
  
  <p>Unfortunately, I get this compile-error that I am unable to solve:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0384]: re-assignment of immutable variable `d`
   --&gt; src/main.rs:4:9
    |
  3 |     for (&amp;mut d, &amp;s) in dst.iter_mut().zip(src.iter()) {
    |               - first assignment to `d`
  4 |         d = s;
    |         ^^^^^ re-assignment of immutable variable
  </code></pre>
  
  <p>How can I set <code>d</code>? Is there a better way to copy a slice?</p>