title: How to get value of next iteration in current iteration in Rust for loop?
body: <p>I have a vector:</p>
  
  <pre><code>let mut v: Vec&lt;Vec&lt;i32&gt;&gt; = Vec::new();
  // [[1, 2, 3], [7, 8, 9], [3, 4, 5], [12, 13, 14], [5, 6, 7]]`
  </code></pre>
  
  <p>I'm trying to sort it to:</p>
  
  <pre><code>// [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9], [12, 13, 14]]
  </code></pre>
  
  <p>I have to reorganize this vector of vectors by the 'continuation' of each last element. The important thing is I can't change position of elements inside vectors. I can change positions of only whole vectors.</p>
  
  <p>How can I get the value of the next iteration in current iteration?</p>
  
  <pre><code>for n in v {
      temp_current_first = n[0];  // OK
      temp_current_last = n[n.len()-1];  // OK
      temp_next_first = n+1[0]; // It's wrong, but something like this
      temp_next_first = n.next()[0] // or this way ??
  }
  </code></pre>