Graph Algorithms
in Pure Rust
1,297 APIs. Zero unsafe. One dependency. Runs natively and in the browser via WASM.
cargo add rust-igraph
1,297 APIs. Zero unsafe. One dependency. Runs natively and in the browser via WASM.
cargo add rust-igraph
use rust_igraph::{Graph, pagerank, louvain};
fn main() {
let g = Graph::from_edges(
&[(0,1), (1,2), (2,0), (2,3), (3,4), (4,5), (5,3)],
false, None
).unwrap();
// Centrality analysis
let pr = pagerank(&g).unwrap();
println!("PageRank: {:?}", pr);
// Community detection
let communities = louvain(&g).unwrap();
println!("Modularity: {:.4}", communities.modularity);
}
use rust_igraph::Graph;
let g = Graph::erdos_renyi(1000, 0.01, 42).unwrap();
// Structural queries
assert!(g.is_connected().unwrap());
println!("Diameter: {:?}", g.diameter().unwrap());
println!("Triangles: {}", g.count_triangles().unwrap());
// Centrality & community
let pr = g.pagerank().unwrap();
let communities = g.louvain().unwrap();
// Graph algebra
let a = Graph::from_edges(&[(0,1)], false, None).unwrap();
let b = Graph::from_edges(&[(1,2)], false, None).unwrap();
let union = &a | &b; // edge union
BFS, DFS, Dijkstra, Bellman-Ford, A*, all-pairs shortest paths, widest paths, topological sort
PageRank, betweenness, closeness, eigenvector, HITS, Katz, harmonic, constraint — 15+ measures
Louvain, Leiden, Infomap, Spinglass, label propagation, Walktrap, edge betweenness, fast greedy, fluid, Voronoi
Max-flow (push-relabel), min-cut, Gomory-Hu tree, edge/vertex connectivity, disjoint paths
VF2 graph/subgraph matching, LAD subgraph, canonical labeling (BLISS), automorphism groups
30+ graph generators, 16 layout engines (FR, KK, DrL, Sugiyama, MDS, UMAP...), spatial algorithms
| rust-igraph | petgraph | igraph (C/Python) | NetworkX | |
|---|---|---|---|---|
| Algorithm scope | 1,297 APIs | ~50 (composable) | ~850 (reference) | ~500 |
| Safety | Zero unsafe | Minimal unsafe | C core + bindings | Memory-safe (Python) |
| Validation | Cross-validated vs igraph C/py/R | Independent tests | Reference impl | Independent tests |
| WASM | Native | Native | Not available | Via Pyodide |
| Dependencies | 1 (thiserror) | Minimal | C/C++ build toolchain | NumPy + SciPy |
Compile to WASM and run graph algorithms client-side — no server needed. Try it live in the playground.
Open Playground