title: Pushing something into a vector depending on its last element
body: <p>I would like to get the last element of a vector and use it to determine the next element to push in. Here's an example how it doesn't work, but it shows what I'm trying to achieve:</p>
  
  <pre><code>let mut vector: Vec&lt;i32&gt; = Vec::new();
  
  if let Some(last_value) = vector.last() {
      vector.push(*last_value + 1);
  }
  </code></pre>
  
  <p>I can't use <code>push</code> while the vector is also borrowed immutably:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0502]: cannot borrow `vector` as mutable because it is also borrowed as immutable
   --&gt; src/main.rs:5:9
    |
  4 |     if let Some(last_value) = vector.last() {
    |                               ------ immutable borrow occurs here
  5 |         vector.push(*last_value + 1);
    |         ^^^^^^ mutable borrow occurs here
  6 |     }
    |     - immutable borrow ends here
  </code></pre>
  
  <p>What would be a good way to do this?</p>