title: Efficiently mutate a vector while also iterating over the same vector
body: <p>I have a vector of structs, and I'm comparing every element in the vector against every other element, and in certain cases mutating the current element. </p>
  
  <p>My issue is that you can't have both a mutable and immutable borrow happening at the same time, but I'm not sure how to reframe my problem to get around this without cloning either the current element or the entire vector, which seems like a waste since I'm only ever mutating the current element, and it doesn't need to be compared to itself (I skip that case).</p>
  
  <p>I'm sure there's an idiomatic way to do this in Rust.</p>
  
  <pre><code>struct MyStruct {
      a: i32,
  }
  
  fn main() {
      let mut v = vec![MyStruct { a: 1 }, MyStruct { a: 2 }, MyStruct { a: 3 }];
  
      for elem in v.iter_mut() {
          for other_elem in v.iter() {
              if other_elem.a &gt; elem.a {
                  elem.a += 1;
              }
          }
      }
  }
  </code></pre>