<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>bilkow</author><text>I think there is a slight mistake in the article:&lt;p&gt;&amp;gt; So how can a reference in a child assume the same lifetime? It can&amp;#x27;t.&lt;p&gt;Well actually, it can, because the owned Struct itself (Node) can outlive any borrow. You won&amp;#x27;t be able to mutate the parent though, as you can&amp;#x27;t mutate any value that has an active immutable borrow. That&amp;#x27;s the problem: you can&amp;#x27;t add the child node as adding it would mutate the parent and the there&amp;#x27;s an active immutable borrow (in the child node).&lt;p&gt;This reddit comment[0] has one possible solution[1] to this problem: not saving all of those parent references in the node itself, only adding when you&amp;#x27;re retrieving it. It also seems a lot better since there&amp;#x27;s less data in-tree to change if the structure itself changes.&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;old.reddit.com&amp;#x2F;r&amp;#x2F;rust&amp;#x2F;comments&amp;#x2F;qstlto&amp;#x2F;rust_data_structures_with_circular_references&amp;#x2F;hkg1omp&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;old.reddit.com&amp;#x2F;r&amp;#x2F;rust&amp;#x2F;comments&amp;#x2F;qstlto&amp;#x2F;rust_data_stru...&lt;/a&gt;
[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;play.rust-lang.org&amp;#x2F;?version=stable&amp;amp;mode=debug&amp;amp;edition=2018&amp;amp;gist=731ab0fcad708964792f4b30e3aef2da&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;play.rust-lang.org&amp;#x2F;?version=stable&amp;amp;mode=debug&amp;amp;editio...&lt;/a&gt;</text><parent_chain></parent_chain></comment><story><title>Rust data structures with circular references</title><url>https://eli.thegreenplace.net/2021/rust-data-structures-with-circular-references/</url></story>
<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>Rusky</author><text>Another interesting variant is a cross between 1 and 2- centralize ownership of the nodes, but continue to use references rather than handles.&lt;p&gt;You can&amp;#x27;t do this with a Vec&amp;lt;Node&amp;gt; (unless you can create all the nodes up front before initializing them) because resizing the Vec would invalidate references into it.&lt;p&gt;But if you use a different &amp;quot;allocator&amp;quot; that leaves its contents in-place, you can make all the links into references with a single lifetime.&lt;p&gt;The remaining tricky part is, still, deallocation- you can&amp;#x27;t fully free a node in a structure like this because they all share a lifetime. But you can put it on a free list for future node allocations, with similar risks to the handle approach.</text><parent_chain></parent_chain></comment><story><title>Rust data structures with circular references</title><url>https://eli.thegreenplace.net/2021/rust-data-structures-with-circular-references/</url></story>