title: How can I use multiple items in a Vec at a time in Rust?
body: <p>I've been fighting with the borrow checker for a little bit... the gist of what I want to do is this:</p>
  
  <pre><code>#[derive(Debug)]
  struct SomeStruct {
      value: String,
  }
  
  impl SomeStruct {
      fn new(value: &amp;str) -&gt; SomeStruct {
          SomeStruct { value: value.to_string() }
      }
  
      fn change_value(&amp;mut self, new_value: &amp;str) {
          self.value = new_value.to_string();
      }
  }
  
  fn main() {
      let mut my_vec = vec![
          SomeStruct::new("foo"),
          SomeStruct::new("bar"),
      ];
  
      my_vec[0].change_value(my_vec[1].value.as_str());
  }
  </code></pre>
  
  <p>This is a very generic version of a problem I'm having. Here's the stderr:</p>
  
  <pre><code>error[E0502]: cannot borrow `my_vec` as immutable because it is also borrowed as mutable
    --&gt; src/main.rs:22:30
     |
  22 |     my_vec[0].change_value(my_vec[1].value.as_str());
     |     ------                 ^^^^^^                  - mutable borrow ends here
     |     |                      |
     |     |                      immutable borrow occurs here
     |     mutable borrow occurs here
  </code></pre>
  
  <p>So the borrow checker doesn't allow me to borrow the vector twice (once as mutable, and then again as immutable), which I understand. But the frustrating thing is that I want to modify one element in the vector, and only read another. I'm new to Rust (surprise!), and I'm not sure I've wrapped my mind around all its details and design choices. But this is something that feels like it should work, yet doesn't. What am I missing, and what can I do to get this (or comparable behavior) to work? Any help is greatly appreciated!</p>