1

I mean a tree where every node has multiple children and every child refers back to its parent.

I've got this far:

pub struct Post {
    content: String,
    links: Vec<Post>,
    parent: Box<Post>,
}

impl Post {
    pub fn new() -> Post {
        Post {
            content: String::new(),
            links: Vec::new(),
            parent: Box::new(......),
        }
    }
}

What do I put in the place of the dots?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
sten
  • 7,028
  • 9
  • 41
  • 63
  • 2
    This is a bit broad; there's an infinite amount of solutions how to implement such a tree, depending on requirements. Could you please add more information what you are trying to achieve, and what specific obstacle you hit? – Sven Marnach Nov 21 '18 at 18:45
  • Duplicate of [What is the paradigmatic way to create a Rust tree with a parent pointer?](https://stackoverflow.com/questions/45108489/what-is-the-paradigmatic-way-to-create-a-rust-tree-with-a-parent-pointer) (which is itself a duplicate of those two questions). – Shepmaster Nov 21 '18 at 18:54
  • 1
    Have you worked through [Learning Rust With Entirely Too Many Linked Lists](http://cglab.ca/~abeinges/blah/too-many-lists/book/)? It will answer many of your questions about the unique problems posed by cyclic data structures in Rust. – trent Nov 21 '18 at 18:55
  • See also [How would you implement a bi-directional linked list in Rust?](https://stackoverflow.com/q/22268861/155423) – Shepmaster Nov 21 '18 at 18:56

0 Answers0