Crate graphsearch [] [src]

A graph representation and search library


use graphsearch::{Graph, Node, Vertex};
let rawgraph = vec![Node{content: "Helsinki",
                         adjacent: vec![Vertex{cost: 20, node: 1},
                                        Vertex{cost: 50, node: 2}]},
                    Node{content: "Turku",
                         adjacent: vec![Vertex{cost: 30, node: 2}]},
                    Node{content: "Tampere",
                         adjacent: Vec::new()}];
let g = Graph::new(rawgraph);
let start  = 0;
let target = "Tampere";
let res =, target); // uses dijkstras algorithm
match res {
  None => {
    println!("Search returned None");
  Some(result) => {
    println!("Search returned a path: {:?}", result);
    println!("The returned path cost: {}", g.cost_of_path(&result));



A graph, represeted by as a weighted Adjacency list of Nodes


A node in the graph, made up a any content type T and a Vec of vertices


A vertex between two Nodes with an associated i32 cost and a target node. Vertex derives Copy, Debug, Eq and PartialEq and implements Ord and PartialOrd as we use it ordered compound types.