3 ms·
How did idiomatic Rust make it hard to implement a doubly-linked list? I don't know Rust, so asking out of curiosity.
by lopatin 2y ago
How did idiomatic Rust make it hard to implement a doubly-linked list? I don't know Rust, so asking out of curiosity.
- Joker_vD 2y agoYou can't very easily have two equivalently powerful pointers that point at the same node in Rust. It became somewhat of a meme in Rust community to the point that there is even a series called "Learn Rust With Entirely Too Many Linked Lists" [0]. [0] https://rust-unofficial.github.io/too-many-lists/ https://rust-unofficial.github.io/too-many-lists/
- SkiFire13 2y agoRust's ownership and borrowing rules really want tree-shaped data, i.e. where there are no cycles. But a doubly-linked list is exactly the opposite of that, each pair of adjacent nodes create a cycle.
- whizzter 2y agoThe memory ownership kinda expects all structures to be in a DAG (ie no cycles since ownership tracking doesn't understand that).