Implement 2022 day 1

This commit is contained in:
2022-12-01 09:32:18 +01:00
parent 2ae2d6baa8
commit 85a51b13c1
6 changed files with 2348 additions and 5 deletions

19
2022/src/common.rs Normal file
View File

@@ -0,0 +1,19 @@
//! Common helper utilities to all days
use anyhow::Result;
use nom::Finish;
use nom::Parser;
/// Parse input from some nom parser and return as an anyhow result
///
/// This method exists as a convenience because nom's errors cannot otherwise be easily converted to
/// an anyhow error, and I don't want to keep track of custom error implementations here.
pub fn parse_input<'a, O>(
input: &'a [u8],
mut parser: impl Parser<&'a [u8], O, nom::error::Error<&'a [u8]>>,
) -> Result<O> {
match parser.parse(input).finish() {
Ok((_, value)) => Ok(value),
Err(err) => anyhow::bail!("Failed to parse at: {err:?}"),
}
}