1
0
Fork 0

Solve day 6

This commit is contained in:
Lars Martens 2023-12-06 14:07:46 +01:00
parent c458652c7a
commit e7f641678a
Signed by: haselkern
GPG key ID: B5CF1F363C179AD4
3 changed files with 101 additions and 0 deletions

View file

@ -1 +1,29 @@
use std::fmt::{Debug, Display};
use std::str::FromStr;
/// Parse a whitespace separated list of things.
///
/// Panics on parse error.
pub fn parse_ws_separated<T>(s: &str) -> impl Iterator<Item = T> + '_
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
s.split_ascii_whitespace().map(|s| s.parse().unwrap())
}
/// Concatenate two things.
///
/// Panics if the concatenation is not be parseable.
///
/// ```rust
/// # use aoc2023::concat;
/// assert_eq!(concat(123, 456), 123456);
/// ```
pub fn concat<T>(a: T, b: T) -> T
where
T: Display + FromStr,
<T as FromStr>::Err: Debug,
{
format!("{a}{b}").parse().unwrap()
}