google / google/comprehensive-rust

Graph can be created in safe Rust very well

Open
#2,955 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
33.4k
Forks
2.1k
Avg merge
1d 3h
Merged PRs (30d)
10

Description

In Unsafe > Motivations > Data Structures, you say that graphs cannot be created in safe Rust. This is false - e.g. [`petgraph`](https://docs.rs/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.