title: How can I change fields of elements in vectors?
body: <p>I have a <code>vec</code> of some struct type and I want to change some field of the first element in the vector. How can I do this?</p>
  
  <p>Example:</p>
  
  <pre><code>struct SomeType {
      some_value: i32,
  }
  
  fn main() {
      let mut vec = Vec::new();
      let mut t = SomeType { some_value: 45 };
      vec.push(t);
  
      println!("Old value: {}", vec.first().unwrap().some_value);
      vec.first().unwrap().some_value += 1;
      println!("New value: {}", vec.first().unwrap().some_value);
  }
  </code></pre>
  
  <p>This fails to compile:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: cannot assign to immutable field
    --&gt; vec.rs:15:2
     |
  15 |    vec.first().unwrap().some_value += 1;
     |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot mutably borrow immutable field
  </code></pre>
  
  <p>I can't get my head around the mutability stuff in Rust yet; what would be the correct approach here?</p>