Similarly getting a mutable reference to a leaf while parents have references to children is awkward
Similarly getting a mutable reference to a leaf while parents have references to children is awkward
smarter sources: https://rust-unofficial.github.io/too-many-lists/ https://softsilverwind.github.io/rust/2019/01/11/Rust-Linked...
In this particular case, borrow checker does it job as designed. So, why to fight it?
The solution is to use an alternative automatic garbage collector instead of compiler built-in: arenas, RC with weak references, or Mark&Sweep GC. Arenas have better performance, because they drop all nodes at once. The easiest way to quickly implement an arena in safe Rust is to use vector (array) of nodes and used indices instead of direct references.
Rust by default forbids cyclic references, by forcing to use trees, which completely avoids the problem.
Linux kernel uses doubly linked lists, Redis uses doubly linked lists, V8 JS engine uses doubly linked lists. Have their authors chosen something obviously wrong?