pub fn read_gml<R: Read>(input: R) -> IgraphResult<Graph>Expand description
Read a graph from GML format.
Parses the first graph [ ... ] block. Extracts directed (0 or 1,
default 0), node [ id N ] entries, and edge [ source N target N ]
entries. Non-structural keys within node/edge blocks (e.g. label,
weight) are stored as vertex/edge attributes.
Node ids need not be contiguous or start at 0 — the reader maps them to internal vertex indices in the order they appear.
§Examples
use rust_igraph::{Graph, read_gml, AttributeValue};
let gml = b"graph [
directed 0
node [ id 1 label \"Alice\" ]
node [ id 2 label \"Bob\" ]
edge [ source 1 target 2 weight 1.5 ]
]";
let g = read_gml(&gml[..]).unwrap();
assert_eq!(g.vcount(), 2);
assert_eq!(g.ecount(), 1);
assert!(!g.is_directed());
assert_eq!(
g.vertex_attribute("label", 0).and_then(|v| v.as_str()),
Some("Alice"),
);
assert_eq!(
g.edge_attribute("weight", 0).and_then(|v| v.as_f64()),
Some(1.5),
);