diff --git a/2024/rust/src/day1.rs b/2024/rust/src/day1.rs index 98ed71c..1c2b3a6 100644 --- a/2024/rust/src/day1.rs +++ b/2024/rust/src/day1.rs @@ -6,6 +6,7 @@ fn main() { show_answers(note.smallests_distances(), note.similarity_score()); } +#[derive(Default)] struct HistorianNote { left: Vec, right: Vec, @@ -14,14 +15,13 @@ struct HistorianNote { impl FromStr for HistorianNote { type Err = ParseIntError; fn from_str(s: &str) -> Result { + let mut result = Self::default(); let mut line_tokens = s.lines().map(|l| l.split_once(" ")); - let mut left = Vec::::new(); - let mut right = Vec::::new(); while let Some((l, r)) = line_tokens.next().flatten() { - left.push(l.parse()?); - right.push(r.parse()?); + result.left.push(l.parse()?); + result.right.push(r.parse()?); } - Ok(Self { left, right }) + Ok(result) } }