Nice. What’s an “isomorphic” data stucture? I’m curious.
I’ll address the unsafe block since you asked. It looks unproblematic if you can guarantee that the parent pointer always is valid, however a closer look at how you get this parent pointer is needed.
You get it from
&mut self in
fn new_contained_node of course. But what this means is if self, the graph, moves, that invalidates the raw pointer!
If you take a graph
g from your testcase and move that
g value (for example push it to a vector), now the parent pointer is invalid.
We can only get a stable parent pointer if we know it’s inside a box or an Rc. If you can make sure
fn new_contained_node or similar is only called on an Rc-graph, then it’s stable. And then you can use a Weak instead too.