aoc: stop printing inside run functions
This will make benching implementations easier
This commit is contained in:
parent
6f06d5d7ca
commit
4bff689da0
21 changed files with 139 additions and 75 deletions
|
|
@ -7,7 +7,7 @@ macro_rules! err {
|
|||
($($string:expr),+) => (Box::<dyn std::error::Error>::from(format!($($string),+)))
|
||||
}
|
||||
|
||||
type DayFunc = fn() -> Result<()>;
|
||||
pub type DayFunc = fn() -> Result<String>;
|
||||
|
||||
pub fn run(days: &[DayFunc]) -> Result<()> {
|
||||
let mut args = env::args();
|
||||
|
|
@ -16,14 +16,16 @@ pub fn run(days: &[DayFunc]) -> Result<()> {
|
|||
match args.next() {
|
||||
Some(arg) => {
|
||||
let day: usize = arg.parse().expect("Please provide a day number");
|
||||
days[day - 1]().unwrap_or_else(|e| eprintln!("error running day specified: {}", e));
|
||||
let res =
|
||||
days[day - 1]().or_else(|e| Err(err!("error running day specified: {}", e)))?;
|
||||
println!("{}", res);
|
||||
}
|
||||
None => {
|
||||
for (i, day) in days.iter().enumerate() {
|
||||
let i = i + 1;
|
||||
println!("day{}: ", i);
|
||||
day().unwrap_or_else(|e| eprintln!("error running day {}: {}", i, e));
|
||||
println!();
|
||||
let res = day().or_else(|e| Err(err!("error running day {}: {}", i, e)))?;
|
||||
println!("{}", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue