1use rugraph::digraph::digraph_from_dot_string;
2use rugraph::digraph::DiGraph;
3use rugraph::rugraph::IDiGraph;
4use rugraph::rugraph::IGraph;
5use std::fs::File;
6
7fn main() {
8 println!("Example of dot file creation. Check test1.dot file.\nTo create a picture install graphivz.\n\n$ dot -Tpng example1.dot -o example1.png\n\n");
9
10 let mut fd = File::create("example1.dot").expect("error creating file");
11 let mut graph = DiGraph::<String>::new();
12 graph.add_node("a".to_string());
13 graph.add_node("b".to_string());
14 graph.add_node("c".to_string());
15 graph.add_node("d".to_string());
16 graph.add_edge("a".to_string(), "b".to_string());
17 graph.add_edge("b".to_string(), "c".to_string());
18 graph.add_edge("c".to_string(), "d".to_string());
19 graph.add_edge("a".to_string(), "d".to_string());
20 println!("Number of nodes of graph {}", graph.count_nodes());
21
22 graph.to_dot_file(&mut fd, &String::from("to_dot_test"));
23 let s = graph.to_dot_string(&String::from("to_dot_test"));
24 println!("File content:\n{}", s);
25
26 println!("Creating a new graph from the file content.");
27
28 let graph2 = match digraph_from_dot_string(&s) {
29 Err(e) => {
30 println!("Error {}",e);
31 return;
32 }
33 Ok(v) => v,
34 };
35 println!("Number of nodes of new graph {}", graph2.count_nodes());
36}