title: How do you borrow a mutable reference during a match?
body: <p>I found <a href="https://stackoverflow.com/questions/22282117/how-do-i-borrow-a-reference-to-what-is-inside-an-optiont-in-rust">this</a> but could not get my code to work. I still have the sneaking suspicion that I need <code>ref</code> somehow.</p>
  
  <p>I am trying to make a reasonable Table class in Rust to learn more about the language and running into some trouble with understanding the borrow checker and mutability concepts as well as their corresponding syntax.</p>
  
  <p>I want the table class to be flexible and allow for different column types where the data types within the columns are homogeneous. So, a column of ints, floats, strings etc.</p>
  
  <hr>
  
  <p>I started without flexible data types and came up with <a href="http://is.gd/a5ezdS" rel="noreferrer">this</a> hashmap mapping ints (the column labels in this case) to vectors of ints (the data within the columns). </p>
  
  <pre class="lang-rust prettyprint-override"><code>use std::collections::HashMap; 
  
  fn main() {
      let mut d: HashMap&lt;isize, Vec&lt;isize&gt;&gt; = HashMap::new();
      d.insert(0, Vec::new());
      d.get_mut(&amp;0).unwrap().push(0); 
  
      println!("{:?}", d);
      // nice {0: [0]}
  }
  </code></pre>
  
  <p>To implement flexible data types, <code>enum</code> seemed like a decent start so <a href="http://is.gd/rmRJQh" rel="noreferrer">that is where I started</a> but I am stuck on the implementation.</p>
  
  <pre class="lang-rust prettyprint-override"><code>use std::collections::HashMap; 
  
  #[derive(Debug)] 
  enum VT {
      A(Vec&lt;isize&gt;),
      B(Vec&lt;f64&gt;),
  }
  
  fn main() {
      let mut d: HashMap&lt;isize, VT&gt; = HashMap::new();
      d.insert(0, VT::A(Vec::new()));
  
      match d.get_mut(&amp;0).unwrap() {
          &amp;mut VT::A(v) =&gt; v.push(0),
          &amp;mut VT::B(v) =&gt; v.push(0.1), // would not be reached as-is 
      } 
  
      println!("{:?}", d);
  }
  // cannot borrow immutable local variable `v` as mutable :(
  </code></pre>
  
  <p>Ultimately, having a library similar to <a href="http://pandas.pydata.org/" rel="noreferrer">pandas</a> would be the dream. For now, implementing a table is good Rust practice.</p>