aoc/
puzzles.rs

1use crate::all_puzzles;
2use utils::date::Date;
3
4// These imports are unused if none of the year features are enabled
5#[allow(clippy::allow_attributes, unused_imports)]
6use utils::{
7    PuzzleDate,
8    input::{InputError, InputType, strip_final_newline},
9};
10
11/// Represents a wrapper function around a puzzle solution.
12///
13/// See [`PUZZLES`].
14pub type PuzzleFn = fn(&str) -> Result<(String, String), InputError>;
15
16macro_rules! matcher {
17    ($(
18        $y:literal => $year:ident{$(
19            $d:literal => $day:ident,
20        )*}
21    )*) => {
22        /// Slice containing all supported puzzle solutions.
23        ///
24        /// Each puzzle is represented by a tuple of [`Date`] and a [`PuzzleFn`], which takes
25        /// an input string and returns the part 1 and 2 solutions as strings, or an [`InputError`].
26        ///
27        /// Generated from [`all_puzzles!`].
28        pub static PUZZLES: &[(Date, PuzzleFn)] = &[$($(
29            (crate::$year::$day::DATE, |input: &str| {
30                let input = strip_final_newline(input);
31                let solution = crate::$year::$day::new(input, InputType::Real)?;
32                let part1 = solution.part1();
33                let part2 = solution.part2();
34                Ok((part1.to_string(), part2.to_string()))
35            }),
36        )*)*];
37    };
38}
39all_puzzles!(matcher);