X-Git-Url: https://i11git.iti.kit.edu/anon-gitweb/?p=Mitarbeiter%2FTim-Zeitz%2Fstud-rust-base.git;a=blobdiff_plain;f=src%2Fbin%2Fexample.rs;h=68056b8c014bc0c2b99f80a884472ac977b31fcb;hp=775d2ca7a85aadccd1b47976cb7b5b4904970ea1;hb=b98ead7d67d4779f4e70b47bdc08a72eb666cf9f;hpb=c56a14307218fbb51ad188826a431cd034cce473 diff --git a/src/bin/example.rs b/src/bin/example.rs index 775d2ca..68056b8 100644 --- a/src/bin/example.rs +++ b/src/bin/example.rs @@ -1,30 +1,29 @@ -extern crate stud_rust_base; +use stud_rust_base::{io::*, time::report_time, types::*}; -use stud_rust_base::{ - types::*, - io::*, - time::report_time, -}; +use std::{env, error::Error, path::Path}; -use std::{env, path::Path}; - -fn main() { +fn main() -> Result<(), Box> { let mut args = env::args(); args.next(); let arg = &args.next().expect("No directory arg given"); let path = Path::new(arg); - let first_out = Vec::::load_from(path.join("first_out").to_str().unwrap()).expect("could not read first_out"); - let head = Vec::::load_from(path.join("head").to_str().unwrap()).expect("could not read head"); - let travel_time = Vec::::load_from(path.join("travel_time").to_str().unwrap()).expect("could not read travel_time"); + let first_out = Vec::::load_from(path.join("first_out"))?; + let head = Vec::::load_from(path.join("head"))?; + let travel_time = Vec::::load_from(path.join("travel_time"))?; report_time("iterating over arcs of some node", || { let node_id = 42; - for &edge_id in &head[first_out[node_id] as usize .. first_out[node_id + 1] as usize] { - println!("There is an arc from {} to {} with weight {}", node_id, head[edge_id as usize], travel_time[edge_id as usize]); + for edge_id in first_out[node_id]..first_out[node_id + 1] { + println!( + "There is an arc from {} to {} with weight {}", + node_id, head[edge_id as usize], travel_time[edge_id as usize] + ); } }); - vec![42; 42].write_to(path.join("distances").to_str().unwrap()).expect("could not write distances"); + vec![42; 42].write_to(&path.join("distances"))?; + + Ok(()) }