From 122e818060a54da0d80346e690a7b35a644a5c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=A9=20Cassiop=C3=A9e=20Gauthier?= Date: Wed, 8 Dec 2021 16:48:54 -0500 Subject: [PATCH] More Clippy --- src/day1.rs | 4 ++-- src/day3.rs | 2 +- src/day4.rs | 9 +++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/day1.rs b/src/day1.rs index 6510021..fc20e33 100644 --- a/src/day1.rs +++ b/src/day1.rs @@ -1,12 +1,12 @@ use std::io::{self, BufRead}; -fn increases(measurements: &Vec) -> u64 { +fn increases(measurements: &[u64]) -> u64 { measurements .windows(2) .fold(0, |acc, x| if x[1] > x[0] { acc + 1 } else { acc }) } -fn convolve(measurements: &Vec) -> Vec { +fn convolve(measurements: &[u64]) -> Vec { measurements.windows(3).map(|x| x.iter().sum()).collect() } diff --git a/src/day3.rs b/src/day3.rs index 18c15d6..a3281a1 100644 --- a/src/day3.rs +++ b/src/day3.rs @@ -21,7 +21,7 @@ impl Diagnostics { u32::from_str_radix(&self.least_common_value(), 2).unwrap() } - fn count_bit(&self, values: &Vec, bit: usize) -> (usize, usize) { + fn count_bit(&self, values: &[String], bit: usize) -> (usize, usize) { values .iter() .fold((0, 0), |acc, x| match x.chars().nth(bit).unwrap() { diff --git a/src/day4.rs b/src/day4.rs index 3159ded..82b55f1 100644 --- a/src/day4.rs +++ b/src/day4.rs @@ -11,13 +11,10 @@ struct Board { } impl Board { - fn mark<'a>(&'a mut self, number: u8) { + fn mark(&mut self, number: u8) { for row in self.grid.iter_mut() { - match row.iter_mut().find(|square| square.number == number) { - Some(square) => { - square.marked = true; - } - None => {} + if let Some(square) = row.iter_mut().find(|square| square.number == number) { + square.marked = true; } } }