graphfind_rs/petgraph/
print.rs1#[cfg(feature = "svg")]
2use graphviz_rust::cmd::{CommandArg, Format};
3use petgraph::dot::Dot;
4use std::fmt::Debug;
5#[cfg(feature = "svg")]
6use std::vec;
7
8use crate::graph::VizDotGraph;
9
10impl<NodeWeight, EdgeWeight, IndexType, Direction> VizDotGraph<NodeWeight, EdgeWeight>
14 for petgraph::graph::Graph<NodeWeight, EdgeWeight, Direction, IndexType>
15where
16 NodeWeight: Debug,
17 EdgeWeight: Debug,
18 IndexType: petgraph::graph::IndexType,
19 Direction: petgraph::EdgeType,
20{
21 fn print(&self) -> String {
23 format!("{:?}", Dot::new(self))
24 }
25
26 #[cfg(feature = "svg")]
33 fn print_to_svg(&self, path: &str) -> Result<String, std::io::Error> {
34 graphviz_rust::exec_dot(
35 self.print(),
36 vec![
37 CommandArg::Format(Format::Svg),
38 CommandArg::Output(path.to_string()),
39 ],
40 )
41 }
42}