-
Couldn't load subscription status.
- Fork 1.9k
Description
In Unsafe > Motivations > Data Structures, you say that graphs cannot be created in safe Rust. This is false - e.g. petgraph is a popular graph library and its graphs are defined entirely using safe Rust. Other cyclic data structures can often be created as well, using indices.
The true thing is that graphs using pointers cannot be written in safe Rust (although this is also not entirely correct, they can be created using arenas, but this is mostly correct). And while we're at it, it's worth emphasizing that using indices in Rust instead of pointers for cyclical data structures is often worth it - it avoids the unsafe code, and sometimes there are even perf gains due to better cache access.