title: How to get multiple mutable references to elements in a Vec?
body: <p>I have a large nested data structure and would like to pluck out a few parts to pass around for processing. Ultimately I want to send sections to multiple threads to update but I'd like to get my feet wet understanding the simple example I illustrate below. In C I would just assemble an array of the relevant pointers. It seems doable in Rust as the interior vectors will never need multiple mutable references. Here's the sample code.</p>
  <pre><code>fn main() {
      let mut data = Data::new(vec![2, 3, 4]);
      // this works
      let slice = data.get_mut_slice(1);
      slice[2] = 5.0;
      println!(&quot;{:?}&quot;, data);
  
      // what I would like to do
      // let slices = data.get_mut_slices(vec![0, 1]);
      // slices[0][0] = 2.0;
      // slices[1][0] = 3.0;
      // println!(&quot;{:?}&quot;, data);
  }
  
  #[derive(Debug)]
  struct Data {
      data: Vec&lt;Vec&lt;f64&gt;&gt;,
  }
  
  impl Data {
      fn new(lengths: Vec&lt;usize&gt;) -&gt; Data {
          Data {
              data: lengths.iter().map(|n| vec![0_f64; *n]).collect(),
          }
      }
  
      fn get_mut_slice(&amp;mut self, index: usize) -&gt; &amp;mut [f64] {
          &amp;mut self.data[index][..]
      }
  
      // doesnt work
      // fn get_mut_slices(&amp;mut self, indexes: Vec&lt;usize&gt;) -&gt; Vec&lt;&amp;mut [f64]&gt; {
      //     indexes.iter().map(|i| self.get_mut_slice(*i)).collect()
      // }
  }
  </code></pre>