5 ms·
The difficulty of writing self-referential data structures in Rust arises on HN often. Every time, the answer is, broadly, the same: - It is certainly difficul
by urschrei 9y ago
The difficulty of writing self-referential data structures in Rust arises on HN often. Every time, the answer is, broadly, the same:
- It is certainly difficult
- Strategies and approaches from low-level languages which are at least cosmetically similar will probably be unavailing
- In some (many?) cases, crates (Rental, Petgraph, Spade) exist that already implement them. Their design can be studied
- There's an entire book (http://cglab.ca/~abeinges/blah/too-many-lists/book/ http://cglab.ca/~abeinges/blah/too-many-lists/book/) devoted to writing linked lists in Rust. It's highly informative
Without wishing to explicitly criticise your approach to learning Rust, I'll note that for the vast majority of programmers, it's likely to be frustrating for quite a while.
- oconnor663 9y agoWorth noting: Many of the examples in that book that required unstable/nightly at the time, now work on stable Rust.
- whyever 9y agoIt is really not difficult if you go the petgraph way. Just use a vector and indices into it instead of references.
- username223 9y agoThat's sort of depressing. "Just make your own virtual memory space to get around Rust's PITA memory management" sounds like giving up.
- OtterCoder 9y agoIf you don't want to manage memory, why are you using any systems language? Python, JS, Go, and any number of other languages will be much kinder to you.
- username223 9y agoWhat I meant to say (hence the downvotes...) is that Rust's "borrow checker" is enough of a nuisance that this graph library replaced memory addresses, i.e. pointers, with indexes into an array, effectively creating its own virtual address space.