3 ms·
> Rust has a big problem with certain data structures. ... The language needs something like "single owner with weak backlink, made safe at compile time". That'
by zozbot234 5y ago
> Rust has a big problem with certain data structures. ... The language needs something like "single owner with weak backlink, made safe at compile time". That's a hard problem.
GhostCell and its variations (QCell, LCell etc.) are meant to address this without resorting to Unsafe Rust. But it's a bit of a hack so far, and yes it would be nice to have a more elegant, language-level solution.
- Animats 5y agoGhostCell is interesting. I need to try that in some test cases. Apparently you can make data structures with backlinks, but the whole structure may be immutable once made. You need to change at least two links as an atomic operation for that. It's hard to express that via a type system hack. Then there's the problem of you got there by following links, and now you want to mutate something. Chasing links is fine if they're read only, but if they're mutable, you have to make sure you don't have a loop of mutable references. Again, this is a non-local analysis kind of problem.