use graph_api_lib::{EdgeReference, EdgeSearch, Graph, VertexReference, VertexSearch};
use graph_api_simplegraph::SimpleGraph;
use graph_api_test::{Edge, Vertex, populate_graph};
fn main() {
let mut graph = SimpleGraph::new();
let refs = populate_graph(&mut graph);
vertex_example(&graph);
edge_example(&graph, refs.bryn);
}
fn vertex_example<G>(graph: &G)
where
G: Graph<Vertex = Vertex, Edge = Edge>,
{
let mut project_count = 0;
graph
.walk()
.vertices(VertexSearch::scan())
.probe(|vertex, _| {
if let Vertex::Project(project) = vertex.weight() {
project_count += 1;
println!("Found project: {}", project.name);
}
})
.count();
println!("Total projects found: {}", project_count);
}
fn edge_example<G>(graph: &G, bryn_id: G::VertexId)
where
G: Graph<Vertex = Vertex, Edge = Edge>,
{
graph
.walk()
.vertices_by_id(vec![bryn_id])
.edges(EdgeSearch::scan())
.probe(|edge, _| {
println!(
"Found edge: {:?} connecting {:?} to {:?}",
edge.weight(),
graph.vertex(edge.tail()).unwrap().id(),
graph.vertex(edge.head()).unwrap().id()
);
})
.count();
}