diff --git a/2023/01/src/part1/mod.rs b/2023/01/src/part1/mod.rs index 899f6d9..669ef38 100644 --- a/2023/01/src/part1/mod.rs +++ b/2023/01/src/part1/mod.rs @@ -3,7 +3,7 @@ use crate::puzzle::Puzzle; #[derive(Debug)] struct NoDigitError<'a>(#[allow(dead_code)]&'a str); -fn first_digit(s: &str) -> Result { +fn first_digit(s: &'_ str) -> Result> { for ch in s.chars() { match ch { '0'..='9' => return Ok(u64::from(ch) - u64::from('0')), @@ -13,7 +13,7 @@ fn first_digit(s: &str) -> Result { Err(NoDigitError(s)) } -fn last_digit(s: &str) -> Result { +fn last_digit(s: &'_ str) -> Result> { for ch in s.chars().rev() { match ch { '0'..='9' => return Ok(u64::from(ch) - u64::from('0')), @@ -23,7 +23,7 @@ fn last_digit(s: &str) -> Result { Err(NoDigitError(s)) } -fn calibration_value(s: &str) -> Result { +fn calibration_value(s: &'_ str) -> Result> { Ok(first_digit(s)? * 10 + last_digit(s)?) } diff --git a/2023/01/src/part2/mod.rs b/2023/01/src/part2/mod.rs index cda6e7b..10d9ebc 100644 --- a/2023/01/src/part2/mod.rs +++ b/2023/01/src/part2/mod.rs @@ -7,7 +7,7 @@ struct NoDigitError<'a>(#[allow(dead_code)] &'a str); const DIGITS: &str = r"([0-9]|one|two|three|four|five|six|seven|eight|nine)"; -fn from_digit(s: &str) -> Result { +fn from_digit(s: &'_ str) -> Result> { Ok(match s { "0" => 0, "1" | "one" => 1, @@ -23,7 +23,7 @@ fn from_digit(s: &str) -> Result { }) } -fn first_digit(s: &str) -> Result { +fn first_digit(s: &'_ str) -> Result> { static RE: LazyLock = LazyLock::new(|| Regex::new(&[r"^.*?", DIGITS, r".*$"].join("")).unwrap()); let captures = RE.captures(s).ok_or(NoDigitError(s))?; @@ -31,7 +31,7 @@ fn first_digit(s: &str) -> Result { from_digit(m.as_str()) } -fn last_digit(s: &str) -> Result { +fn last_digit(s: &'_ str) -> Result> { static RE: LazyLock = LazyLock::new(|| Regex::new(&[r"^.*", DIGITS, r".*?$"].join("")).unwrap()); let captures = RE.captures(s).ok_or(NoDigitError(s))?; @@ -39,7 +39,7 @@ fn last_digit(s: &str) -> Result { from_digit(m.as_str()) } -fn calibration_value(s: &str) -> Result { +fn calibration_value(s: &'_ str) -> Result> { Ok(first_digit(s)? * 10 + last_digit(s)?) } diff --git a/bag/src/lib.rs b/bag/src/lib.rs index b3bccad..94d7efb 100644 --- a/bag/src/lib.rs +++ b/bag/src/lib.rs @@ -28,7 +28,7 @@ impl Bag { self.0.values().sum() } - pub fn iter(&self) -> Iter { + pub fn iter(&'_ self) -> Iter<'_, T> { self.0.iter() } }