by zyxzevn · 8y ago · 0 comments
Basic Rust does not allow cyclic references, which means that almost every graph needs to use special tricks to make it work. These tricks are variants of reference counting. A trick that was copied directly from C++.
It feels like having to build a car with only a screwdriver and hammer. Each section of your graph needs to be managed separately. With non-safe rust or C++ you can put whole panels or sections on your car. And a garbage collector works like a robot: usually effortless.
And if your nodes can be of different types, you probably need to make them "enums" instead of "objects".
So essentially you need these tricks to work with graphs, which means that your program design is really not as easy as with a garbage collected system, or manual memory management.
I think that many new users have problems with complex graphs in Rust, especially cycled graphs.
The tricky things are only if you want to have 2-way pointers without refcounting overhead.