2 ms·
If the last time you tried it was 5 years ago, then you probably didn't experience Rust with non-lexical lifetimes. That was added in around 2018 (IIRC), and ra
by woodruffw 4y ago
If the last time you tried it was 5 years ago, then you probably didn't experience Rust with non-lexical lifetimes. That was added in around 2018 (IIRC), and radically increased the number of programs that the borrow checker accepted.
That being said, you still can't do "naive" cyclical data structures without some additional assistance. But the ecosystem has matured around that: crates like ouroboros[1] provide safe interfaces for creating self-referential structures and datatypes.
Edit: NLL was indeed added in the 2018 Edition[2].
[1]: https://docs.rs/ouroboros/latest/ouroboros/ https://docs.rs/ouroboros/latest/ouroboros/
[2]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#non-lexical-lifetimes https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-201...
- ChadNauseam 4y agoGhost-cell [0] also lets you create a doubly-linked lists (without you having to use unsafe code, and with no overhead) [0]: https://crates.io/crates/ghost-cell https://crates.io/crates/ghost-cell
- xavxav 4y agoYea but it’s not really useable in practice as it heavily relies on nesting allocations in closures to simulate “generative lifetimes”. It’s a research artifact, not meant for serious usage. Instead, I would recommend using something like https://crates.io/crates/qcell https://crates.io/crates/qcell, which works on similar principles.