Regarding everything being destructed at once: that’s called an arena, and there are crates for it:
Regarding everything being destructed at once: that’s called an arena, and there are crates for it:
Thats such a great name :)
What you do is you put all of your tree nodes in a big Vec<Node> and instead of referring to children and parents via pointers, you do so via indices. It's less convenient because you have to pass around a reference to your "arena" everywhere (the Vec or a slice of it), and it incurs bounds checks (pretty cheap though). But, it solves the problem in a way that is guaranteed safe.
However, you must have interior mutability (achieved using Cell types), because otherwise you can't mutate the parent nodes to add links to child nodes.
Check the typed arena crate in crates.io and the Cell type in the standard library.