Comment

Comment by lumost

The linked list debate should really be improved. From a practical perspective there are many reasons why one may wish to model a cyclic, linked datastructure.

Simple examples:

You have a social networking site that you are prototyping. You choose to start your data model with a simple Person struct which contains a list of Person called friends.

You have an e-commerce site and choose a data model which has a User struct which contains a Cart reference, and a Cart struct containing a User reference for its owning user.

You have any problem which involves a graph data-structure.

In Rust the best way to work around these issues is to have explicit lookup's by id rather than direct traversable references, or use unsafe. There are no other mechanisms. It's a missing feature that really should be highlighted early in the docs or even as a compiler error such as "cyclic ownership detected in Struct X -> References Y -> References Z in main.rs#128 consider removing the cycle or using Rc, Arena, or unsafe allocations"

As it stands if you create a reference cycle in rust you'll get a ton of compiler errors that force you to learn the rest of the ownership rules just to find out that this is something you can never do.

parent lumost 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton