From 5bb3c2974166c9f8433e26a3271b97ef8fa465bf Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Mon, 2 Dec 2024 10:18:54 -0600 Subject: [PATCH] Cleaner --- 2024/rust/src/day1.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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) } }