title: How can I return boxed value?
body: <p>I basically have a function that creates some object which need to be allocated on the heap. What I want to do is return from that function a structure containing a reference to that heap-allocated value.</p>
  
  <pre><code>struct Cont&lt;'a&gt; {
      pub v: &amp;'a i32
  }
  
  impl&lt;'a&gt; Cont&lt;'a&gt; {
      fn new(v: &amp;'a i32) -&gt; Cont {
          Cont {
              v: v
          }
      }
  }
  
  fn f&lt;'a&gt;() -&gt; Cont&lt;'a&gt; {
      let v = Box::new(6);
  
      Cont::new(&amp;v)
  }
  
  fn main() {
      let c = f();
  
      println!("{}", c.v);
  }
  </code></pre>
  
  <p>I'm getting <code>error: 'v' does not live long enough</code>.</p>
  
  <p>You can find the example <a href="http://is.gd/R9Ps1d" rel="nofollow">here</a>.</p>