The Rust Book has an example: https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
Of course, leaking memory is as easy as using `Box::leak`, although that's probably never going to happen accidentally.
Re:Welcome to Comprehensive Rust
by britneybitch on Thursday December 22, 2022 @08:27AM
(#34092982)
You could store a `RefCell<Option<T>>` in an `Rc` and set it to `Some(rc)` after creation.
Or you could use the recently-stabilized `new_cyclic` method: https://doc.rust-lang.org/std/rc/struct.Rc.html#method.new_c...
Re:Welcome to Comprehensive Rust
by bitexploder on Thursday December 22, 2022 @08:36AM
(#34093044)
And when using C libraries / FFI, there are a lot of tricky things going in, it is much easier to leak in unsafe land.
It should not be possible with normal borrows (and safe Rust) since they're statically checked to be acyclic.