Skip to content

Graph can be created in safe Rust very well #2955

@ChayimFriedman2

Description

@ChayimFriedman2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions