title: return a reference value from a function in rust
body: <p>I'm working on a pdf generation application. I have a struct (Document) that owns all pages. Whenever i want to add a page i also want give the caller a borrowed value of the page back, so the document still is the owner of the struct. Like returning a pointer in C. </p>
  
  <pre><code>pub struct Document {
      pages: Vec&lt;Page&gt;,
      totalPages: i32,
      _secret: ()
  }
  
  
  pub fn add_page(&amp;mut self, dimension: PageDimension) -&gt; &amp;mut Page {
      let newPage = Page::new(self.pages.len(), dimension);
      self.pages.push(newPage);
      newPage
  }
  </code></pre>
  
  <p>Can anyone explain how to achieve what i want. </p>