title: How do I pass an array to a function in Rust and change its content?
body: <p>I want to pass an array to a function and change the content inside it:</p>
  <pre class="lang-rust prettyprint-override"><code>fn change_value(mut arr: &amp;[i32]) {
      arr[1] = 10;
  }
  
  fn main() {
      let mut arr: [i32; 4] = [1, 2, 3, 4];
      change_value(&amp;arr);
      println!(&quot;this is {}&quot;, arr[1]);
  }
  </code></pre>
  <p>I'm getting this error:</p>
  <pre class="lang-none prettyprint-override"><code>warning: variable does not need to be mutable
   --&gt; src/main.rs:2:17
    |
  2 | fn change_value(mut arr: &amp;[i32]) {
    |                 ----^^^
    |                 |
    |                 help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default
  
  error[E0594]: cannot assign to `arr[_]` which is behind a `&amp;` reference
   --&gt; src/main.rs:3:5
    |
  2 | fn change_value(mut arr: &amp;[i32]) {
    |                          ------ help: consider changing this to be a mutable reference: `&amp;mut [i32]`
  3 |     arr[1] = 10;
    |     ^^^^^^^^^^^ `arr` is a `&amp;` reference, so the data it refers to cannot be written
  
  warning: variable does not need to be mutable
   --&gt; src/main.rs:7:9
    |
  7 |     let mut arr: [i32; 4] = [1, 2, 3, 4];
    |         ----^^^
    |         |
    |         help: remove this `mut`
  </code></pre>
  <p>I've been searching around, but I can't find anything.</p>