Skip to main content

god_graph/export/
edge_list.rs

1//! 边列表格式导出
2
3use crate::graph::traits::GraphQuery;
4use crate::graph::Graph;
5use std::fmt::Write;
6
7/// 将图导出为边列表格式字符串
8pub fn to_edge_list<T, E>(graph: &Graph<T, E>) -> String
9where
10    T: std::fmt::Display,
11    E: std::fmt::Display,
12{
13    let mut output = String::new();
14
15    for edge in graph.edges() {
16        writeln!(
17            &mut output,
18            "{} {} {}",
19            edge.source().index(),
20            edge.target().index(),
21            edge.data()
22        )
23        .unwrap();
24    }
25
26    output
27}