title: How to store recursive ref inside of a struct
body: <p>Let's assume the following struct</p>
  
  <pre><code>struct Item&lt;'a&gt; {
      items: Vec&lt;&amp;'a Item&lt;'a&gt;&gt;
  }
  </code></pre>
  
  <p>Let's assume the following variable contains many <code>Item</code> objects with empty <code>items</code> field.</p>
  
  <pre><code>let mut items: Vec&lt;Item&lt;'a&gt;&gt; = get_items();
  </code></pre>
  
  <p>Let's assume I have the task to add to <code>items</code> field of each <code>Item</code> the references to all another <code>Item</code> objects in the <code>items</code> vector.</p>
  
  <p>My current implementation is</p>
  
  <pre><code>struct Item&lt;'a&gt; {
      items: Vec&lt;&amp;'a Item&lt;'a&gt;&gt;,
  }
  
  impl&lt;'a&gt; Item&lt;'a&gt; {
      fn new() -&gt; Item&lt;'a&gt; {
          Item { items: vec![] }
      }   
  }
  
  fn main() {
      let mut items = vec![Item::new(), Item::new()];
      while let Some(item) = items.pop() {
          for another_item in &amp;mut items {
              item.items.push(another_item); 
          }   
          items.push(item);
      }   
  }`
  </code></pre>
  
  <p>It fails because I do <code>item.items.push(another_item);</code></p>