Skip to main content

write_gml

Function write_gml 

Source
pub fn write_gml<W: Write>(graph: &Graph, writer: &mut W) -> IgraphResult<()>
Expand description

Write a graph in GML format.

Produces a valid GML file with graph [ directed 0/1 node [ id N ] ... edge [ source N target N ] ... ]. Node ids are the internal vertex indices (0-based).

§Examples

use rust_igraph::{Graph, write_gml, read_gml};

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

let mut buf = Vec::new();
write_gml(&g, &mut buf).unwrap();
let s = String::from_utf8(buf).unwrap();
assert!(s.contains("directed 1"));

// Round-trip
let g2 = read_gml(s.as_bytes()).unwrap();
assert_eq!(g2.vcount(), 3);
assert_eq!(g2.ecount(), 2);
assert!(g2.is_directed());