Skip to main content

Module strvector

Module strvector 

Source
Expand description

Owned vectors of strings (igraph_strvector_t, igraph_strvector.h).

igraph uses string vectors for vertex names, file formats and string attributes. StrVector owns a copy of every string, is indexed with sv[i] (a &str), and offers the usual editing operations (push, set, remove, pop, swap, select, append, extend_from, resize, truncate, clear, …). Strings are stored as C strings: an interior NUL byte truncates a string when it is read back.

use igraph::prelude::*;

let mut names: StrVector = ["alice", "bob"].into_iter().collect();
names.push("carol");
assert_eq!(names.len(), 3);
assert_eq!(names.get(1), Some("bob"));
assert_eq!(names.to_vec(), vec!["alice", "bob", "carol"]);

§Not wrapped

A few functions of igraph_strvector.h have no direct counterpart: igraph_strvector_set and igraph_strvector_push_back take NUL-terminated C strings, while a Rust &str has no terminator, so set and push call the length-taking igraph_strvector_set_len and igraph_strvector_push_back_len instead; igraph_strvector_swap (exchanging two whole vectors) is std::mem::swap; and igraph_strvector_print / igraph_strvector_fprint are covered by the Display implementation, which prints the list as ["alice", "bob"] (igraph’s one-string-per-line format is sv.iter().collect::<Vec<_>>().join("\n")).

Type Aliases§

StrVector
Owned vector of strings (igraph_strvector_t).