Why writing a linked list in safe Rust is so damned hard
Yeah, a doubly-linked list is basically the worst possible choice for your first program in Rust. This is because Rust likes all of your memory to have one clear owner. And this means that cyclic data structures are unusually difficult compared to almost any other first program you might choose.<p>But if you really want to know how to do it, there&#x27;s a really good tutorial on the subject titled &quot;Learning Rust With Entirely Too Many Linked Lists&quot;: <a href="http:&#x2F;&#x2F;cglab.ca&#x2F;~abeinges&#x2F;blah&#x2F;too-many-lists&#x2F;book&#x2F;" rel="nofollow">http:&#x2F;&#x2F;cglab.ca&#x2F;~abeinges&#x2F;blah&#x2F;too-many-lists&#x2F;book&#x2F;</a><p>This will walk you through multiple different kinds of linked lists, and show you how to implement each in Rust. Along the way, you&#x27;ll learn more about Rust&#x27;s ownership system than most working Rust programmers generally need to know.<p>Personally, I&#x27;ve written quite a bit of production Rust code, and I&#x27;ve done so without ever touching &#x27;unsafe&#x27; or needing a linked list. If I really did need a linked list, I&#x27;d either grab a good one off crates.io, or just knock out a quick one using `unsafe` and raw pointers. I mean, Rust can do basically anything C does if I ask nicely. It&#x27;s just that if I choose to write &quot;C in Rust&quot;, then I get about same safety guarantees that C offers.