Skip to main content

write_graphml

Function write_graphml 

Source
pub fn write_graphml<W: Write>(
    graph: &Graph,
    labels: Option<&[String]>,
    writer: &mut W,
) -> IgraphResult<()>
Expand description

Write a graph in GraphML format.

Outputs valid GraphML XML with node and edge elements. If labels is provided, uses them as node IDs; otherwise uses n0, n1, etc.

§Examples

use rust_igraph::{Graph, write_graphml};

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();

let mut buf = Vec::new();
write_graphml(&g, None, &mut buf).unwrap();
let s = String::from_utf8(buf).unwrap();
assert!(s.contains("<graphml"));
assert!(s.contains("edgedefault=\"undirected\""));
assert!(s.contains("<node id=\"n0\""));