Function demes::load

source ·
pub fn load<T: Read>(reader: T) -> Result<Graph, DemesError>
Expand description

Build a Graph from a type implementing Read.

Errors

Returns DemesError in the event of invalid input.

Examples

// We can load graphs from in-memory data in YAML format:
let yaml = "
time_units: generations
demes:
 - name: ancestor
   epochs:
    - start_size: 100
 - name: derived
   start_time: 50
   ancestors: [ancestor]
   epochs:
    - start_size: 10
";
// A slice of raw bytes implements std::io::BufReader
// which implements Read
let raw_bytes: &[u8] = yaml.as_bytes();
let graph = demes::load(raw_bytes).unwrap();
// We can also read from files:
let file = std::fs::File::open("model.yaml").unwrap();
let graph_from_file = demes::load(file).unwrap();