title: When and how to use a vector of references
body: <p>This code correctly compiles.  It has a few unused code warnings, but that's okay for now.</p>
  
  <pre><code>use std::collections::BTreeMap;
  
  enum Object&lt;'a&gt; {
      Str(String),
      Int(i32),
      Float(f32),
      Vector(Vec&lt;&amp;'a Object&lt;'a&gt;&gt;),
      Prim(fn(State) -&gt; State)
  }
  
  struct State&lt;'a&gt; {
      named: BTreeMap&lt;String, &amp;'a Object&lt;'a&gt;&gt;,
      stack: Vec&lt;Object&lt;'a&gt;&gt;
  
  }
  
  impl&lt;'a&gt; State&lt;'a&gt; {
      fn push_int(&amp;mut self, x: i32) {
          self.stack.push(Object::Int(x));
      }
  }
  
  
  fn main() {
      println!("Hello, world!");
      let obj = Object::Str("this is a test".to_string());
  }
  </code></pre>
  
  <p>The important part of this code  is <code>push_int</code> and <code>stack: Vec&lt;Object&lt;'a&gt;&gt;</code>.</p>
  
  <p>I'm sort of trying to make a stack-based VM.
  I want to pass the state to functions, which can take stuff off the stack, manipulate the stuff, and then put some stuff back on the stack; the named field is going to hold named objects.</p>
  
  <p>I have a hunch that it would be better to have the stack represented as a <code>Vec&lt;&amp;'a Object&lt;'a&gt;&gt;</code> instead.
  The way I have it now, I fear I'm committing some inefficiency error. Is my hunch correct?</p>
  
  <p>The second part of the problem is that I don't know how to get the vector of references version to work.  Creating new value with the right lifetimes to push onto the stack is not working for me.</p>
  
  <p>I'm a bit vague about this issue, so if I've been unclear, ask me questions to clear stuff up.</p>