Hacker News new | ask | show | jobs
by johncolanduoni 3535 days ago
Rust is horrifically bad at dealing with non-trivial cyclical structures for a number of reasons, not having a GC being one of them.
1 comments

Beyond "not having GC", what are those reasons? I'm new to Rust and curious...
See http://smallcultfollowing.com/babysteps/blog/2015/04/06/mode... and its linked post; they cover some of the ways you can write general graphs in Rust. It's a bit differently than you'd do it elsewhere.

Of course, if you're willing to give up some safety internally, you can also implement them the same was as you could in C or C++.

Inherited mutability and no aliasing mean cyclical structures tend to be a fairly complicated mess of RefCell/Cells. The borrow checker is very good at handling ordered lifetimes but cannot handle more complicated access patterns without the runtime checks in RefCells.

There are graph libraries, but these only help with structures that are graphs in the strict sense (all edges are created equal and not actually part of the structure) as opposed to structs with one or more fields that reference (and have shared ownership of) another node in the graph.