Self-referential rust data structures

Wed, Apr 22 2026

Here is a candid shot of me reading this blog post about the pain of self-referential data structures in rust.

Self-referential rust data structure meme.

Seeing someone who clearly knows more than me also struggle here was very validating. It's interesting that once you get into this space, the same names, blog posts and techniques start popping up. It's full of tradeofs. Are you ok with not freeing individual items in your self-referential structure? Do you need stuff to be shared across threads? Are you OK with leaking your use of an arena to users of your library? Do you have brain cells to spare?

My own experience in this comes from evolving my very own HTML toolkit. One of the things the library allows you to do is construct and manipulate HTML nodes. To do this you need to build a DOM-like structure, which implies parent, sibling, and child pointers. I've re-implemented this library at least three times. Once using bumpalo, another time using a plain Vec with indices and the third (and final) time using strong/weak pointers. The first two were techniques covered in the blog post.

I admit that once the article wandered into "Generativity", my eyes starting glazing over. I don't doubt that for the author's use case, the type gymnastics become necessary. And really, that's the point of their talk. But there is a sad user experience cliff here I think. The other option would be to give up and use unsafe, but then you'd have ​g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨe̠̅s problems.