Skip to main content

write_ncol

Function write_ncol 

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

Write a graph in NCOL format.

If names is provided, uses them as vertex labels; otherwise uses numeric ids as strings. If weights is provided (one per edge), appends the weight after each edge.

ยงExamples

use rust_igraph::{Graph, write_ncol};

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

let names = vec!["A".to_string(), "B".to_string(), "C".to_string()];
let mut buf = Vec::new();
write_ncol(&g, Some(&names), None, &mut buf).unwrap();
let s = String::from_utf8(buf).unwrap();
assert!(s.contains("A B"));
assert!(s.contains("B C"));