Skip to content

Commit

Permalink
aoc: add "elapsed" function
Browse files Browse the repository at this point in the history
  • Loading branch information
lpenz committed Dec 17, 2023
1 parent 0d48c75 commit f871b2c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aoc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ impl<T> OptionExt<T> for Option<T> {
}
}

pub fn elapsed(start: &Instant) -> String {
format!("{}", humantime::Duration::from(start.elapsed()))
}

pub fn do_main<F: Fn() -> Result<T>, T: Display>(f: F) -> Result<()> {
color_eyre::install()?;
let start = Instant::now();
println!("{}", f()?);
println!("Elapsed: {}", humantime::Duration::from(start.elapsed()));
println!("Elapsed: {}", elapsed(&start));
Ok(())
}

0 comments on commit f871b2c

Please sign in to comment.