Cyclic graphs are hard in Rust. A lovely post demonstrating how to use arenas in Rust to build mutable graphs whilst managing lifetimes correctly:
miniblog.
Related Posts
How do you calculate the length of a singly-linked list that may be cyclic? CLHS includes a nice implementation: https://clhs.lisp.se/Body/f_list_l.htm