This has been released for a while but we never made a proper announcement for it, so:
Selfref
Selfref is a stable (rust 1.65.0+) no-std and no-alloc crate for self-referential and back-referential structs. What's a back-referential struct? Well, sometimes, in C, you have something like this:
struct server;
struct context {
struct server *server;
}
struct server {
struct context **contexts;
}
And the invariant is that the context always has a pointer back to the server that owns it. This is useful because it allows passing the context (by pointer) and getting access to the server and whatnot.
Well, selfref
supports this! In fact it's the primary use-case! In fact other crates tend not to support this! You can see a full example in the docs: selfref - Rust
Selfref 0.4 is likely the last update selfref
is gonna need for a long time. The only reason it's not 1.0 yet is because it relies on not-quite-fleshed-out language implementation details, which could break in a future Rust version. However, these details would not affect selfref
's public API, so just keep an eye on rustsec for any advisories about needing to up the point release. Further, once these details are finalized, all selfref
versions/branches will be updated for it - from 0.1 to 0.4 - and 1.0 will be released.
Changelog (full)
Selfref 0.4.x
Use closures for new_with
Selfref 0.3.x
Use closures for operate_in
Selfref 0.2.x
Support ?Sized
Selfref 0.2.2
Support stable Rust