From e101dbd58cb7f3dcaab1b2a416f8e25cc27832b2 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 9 Dec 2018 10:49:04 +0100 Subject: [PATCH] Move get_impl to crate. --- 2018/src/lib.rs | 29 +++++++++++++++++++++++++++++ 2018/src/main.rs | 31 +------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/2018/src/lib.rs b/2018/src/lib.rs index 68ba7fa..2c446d2 100644 --- a/2018/src/lib.rs +++ b/2018/src/lib.rs @@ -12,3 +12,32 @@ pub mod day06; pub mod day07; pub mod day08; pub mod day09; + +pub fn get_impl(day: u32) -> Box { + match day { + 1 => Box::new(day01::Day01::new()), + 2 => Box::new(day02::Day02::new()), + 3 => Box::new(day03::Day03::new()), + 4 => Box::new(day04::Day04::new()), + 5 => Box::new(day05::Day05::new()), + 6 => Box::new(day06::Day06::new()), + 7 => Box::new(day07::Day07::new()), + 8 => Box::new(day08::Day08::new()), + 9 => Box::new(day09::Day09::new()), + val => panic!("Unimplemented day {}", val), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_impl() { + // Verify that we can load all days + let last_implemented = 8; + for d in 1..=last_implemented { + get_impl(d); + } + } +} diff --git a/2018/src/main.rs b/2018/src/main.rs index df24b34..63a1c43 100644 --- a/2018/src/main.rs +++ b/2018/src/main.rs @@ -6,25 +6,10 @@ use std::fs; use std::io; use std::time::Instant; -use aoc_2018::*; +use aoc_2018::get_impl; use clap::Arg; -fn get_impl(day: u32) -> Box { - match day { - 1 => Box::new(day01::Day01::new()), - 2 => Box::new(day02::Day02::new()), - 3 => Box::new(day03::Day03::new()), - 4 => Box::new(day04::Day04::new()), - 5 => Box::new(day05::Day05::new()), - 6 => Box::new(day06::Day06::new()), - 7 => Box::new(day07::Day07::new()), - 8 => Box::new(day08::Day08::new()), - 9 => Box::new(day09::Day09::new()), - val => panic!("Unimplemented day {}", val), - } -} - fn main() { let matches = app_from_crate!() .arg(Arg::with_name("day") @@ -64,17 +49,3 @@ fn main() { } println!("{}", result); } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_get_impl() { - // Verify that we can load all days - let last_implemented = 8; - for d in 1..=last_implemented { - get_impl(d); - } - } -}