title: Get mutable reference from immutable array
body: <p>I don't know if I phrased the title correctly, but here's the issue:</p>
  
  <pre><code>let mut rows: Vec&lt;Box&lt;String&gt;&gt; = vec![];
  
  let row1 = &amp;mut **rows.get(0).unwrap();
  </code></pre>
  
  <p>I want to store mutable references to multiple strings which are stored in boxes in the vector. This should be perfectly safe since I'm not referencing anything in the vector, just getting a box from the vector, dereferencing it and changing the memory it points to. If the vector gets too large and needs to reallocate its data my strings stay intact. But rust's compiler won't let me  do that, I get the error <code>cannot borrow data in a '&amp;' reference as mutable</code></p>
  
  <p>How do I design around this?</p>
  
  <p>I could make <code>rows</code> mutable and use <code>get_mut</code>, but then I wouldn't be able to, for example, have mutable references to two rows at the same time:</p>
  
  <pre><code>let mut rows: Vec&lt;Box&lt;String&gt;&gt; = vec![];
  
  let row1 = &amp;mut **rows.get_mut(0).unwrap();
  let row2 = &amp;mut **rows.get_mut(1).unwrap();
  
  *row1 = String::from("aaa");
  *row2 = String::from("bbb");
  </code></pre>
  
  <p>This gives <code>cannot borrow 'rows' as mutable more than once at a time</code>.</p>
  
  <p>Another solution would be to get each row only when I need to use it and then get it again if I need to use it again, but I don't think that's a very performant idea since I'd have to loop through the array to find the row I want every time I need to change something in it (I wouldn't be getting the array element by index).</p>
  
  <p><strong>EDIT</strong>: I am trying to design around storing mutable references to the strings, since Rust's compiler won't let me do that. Either I'm missing something I can do to have multiple mutable references to the strings or I need find another way to accomplish that. I need to have mutable references to what the boxes contain, in my program they're not strings, they're structs which have mutable functions, but I used strings here for the sake of simplicity. Here's a bit of code to clarify it</p>
  
  <pre><code>struct Table
  {
      cols: Vec&lt;Box&lt;Col&gt;&gt;
  }
  
  //...
  
  let mut table = Table::new();
  
  let mut id_col          = table.new_col("ID"        .to_owned());
  let mut status_col      = table.new_col("Status"    .to_owned());
  let mut title_col       = table.new_col("Title"     .to_owned());
  let mut deadline_col    = table.new_col("Deadline"  .to_owned());
  let mut tags_col        = table.new_col("Tags"      .to_owned());
  let mut repeat_col      = table.new_col("Repeat"    .to_owned());
  </code></pre>
  
  <p>(I used rows in my first example to make it easier to understand)
  I will iterate over some data and append stuff to these columns, so I don't want to search for them by name in the vector in each iteration, I want to have "cached" references to them (which are all of these variables). The problem is that my compiler won't let me do that because I can't borrow table as mutable more than once. So I mean by "designing around" is changing my way of thinking and restructuring my code so I don't have this problem.</p>