Writing self-referential structs in Rust is a complete nightmare; the borrow checker won't let you do it natively. Testing three common workarounds for this pattern. Which approach do you actually commit to?
Version 1: Unsafe & Raw Pointers
No dependencies; total control but requires manual safety audits.
Offsets feel like a workaround that loses type expressiveness; raw pointers are an open invitation for UB. Is using a macro crate the only sane path forward; or do you just refactor the data flow to avoid this entirely?
You should probably link to the discussion on reddit (and any other sites). I forget if that suggestion is explicitly written down anywhere here.
Anyway, the brief version of my comment on reddit is basically “I prefer generics over macros, so I prefer yoke’s approach”.
Admittedly… I actually switched from yoke to manual unsafe in my formerly-largest usage of yoke, since that use case also required some unsafe for two other purposes (so what’s one more?).
I've never needed a self-referential struct, possibly because I almost always use indices whenever I get to that point, so self-referencing isn't even considered. If I had to, though, I would definitely go with ouroboros or yoke. Self-referential types are notoriously easy to screw up, so I would much rather use code that hundreds of people have vetted.