updates, clippy, formatting
[Mitarbeiter/Tim-Zeitz/stud-rust-base.git] / src / bin / example.rs
1 use stud_rust_base::{io::*, time::report_time, types::*};
2
3 use std::{env, error::Error, path::Path};
4
5 fn main() -> Result<(), Box<dyn Error>> {
6     let arg = &env::args().nth(1).expect("No directory arg given");
7     let path = Path::new(arg);
8
9     let first_out = Vec::<EdgeId>::load_from(path.join("first_out"))?;
10     let head = Vec::<NodeId>::load_from(path.join("head"))?;
11     let travel_time = Vec::<Weight>::load_from(path.join("travel_time"))?;
12
13     report_time("iterating over arcs of some node", || {
14         let node_id = 42;
15         for edge_id in first_out[node_id]..first_out[node_id + 1] {
16             println!(
17                 "There is an arc from {} to {} with weight {}",
18                 node_id, head[edge_id as usize], travel_time[edge_id as usize]
19             );
20         }
21     });
22
23     vec![42; 42].write_to(&path.join("distances"))?;
24
25     Ok(())
26 }