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, including attributes.

If labels is provided, uses them as node IDs; otherwise uses n0, n1, etc. Graph, vertex, and edge attributes from the attribute system are written as <key> definitions and <data> elements.

ยงExamples

use rust_igraph::{Graph, write_graphml, AttributeValue};

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.set_vertex_attribute("label", 0, "Alice".into()).unwrap();
g.set_vertex_attribute("label", 1, "Bob".into()).unwrap();
g.set_vertex_attribute("label", 2, "Carol".into()).unwrap();
g.set_edge_attribute("weight", 0, 1.5.into()).unwrap();

let mut buf = Vec::new();
write_graphml(&g, None, &mut buf).unwrap();
let s = String::from_utf8(buf).unwrap();
assert!(s.contains("attr.name=\"label\""));
assert!(s.contains("attr.name=\"weight\""));
assert!(s.contains("<data key="));