advent-of-code/aoc2019/src/main.rs

31 lines
756 B
Rust
Raw Normal View History

2019-12-01 16:03:34 +01:00
use std::env;
use aoc2019::day01;
2019-12-02 11:50:39 +01:00
use aoc2019::day02;
2019-12-01 16:03:34 +01:00
use aoc2019::Result;
fn main() -> Result<()> {
2019-12-02 11:50:39 +01:00
let days: &[fn() -> Result<()>] = &[day01::run, day02::run];
2019-12-01 16:03:34 +01:00
let mut args = env::args();
args.next();
match args.next() {
Some(arg) => {
let day: usize = arg.parse().expect("Please provide a day number");
2019-12-02 11:48:24 +01:00
days[day - 1]().unwrap_or_else(|e| eprintln!("error running day specified: {}", e));
2019-12-01 16:03:34 +01:00
}
None => {
for (i, day) in days.iter().enumerate() {
let i = i + 1;
println!("day{}: ", i);
2019-12-02 11:48:24 +01:00
day().unwrap_or_else(|e| eprintln!("error running day {}: {}", i, e));
2019-12-01 16:03:34 +01:00
println!();
}
}
}
Ok(())
}