From f43530b29706a7dbb30dafaad32e4f8cf14241f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sp=C3=B6ttel?= <1682504+fspoettel@users.noreply.github.com> Date: Mon, 11 Dec 2023 09:43:59 +0100 Subject: [PATCH] chore: address some `clippy::pedantic` warnings (#55) --- src/template/commands/all.rs | 2 +- src/template/commands/scaffold.rs | 2 +- src/template/commands/time.rs | 27 +++++++++++++++------------ src/template/run_multi.rs | 2 +- src/template/timings.rs | 6 +++--- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/template/commands/all.rs b/src/template/commands/all.rs index 444497d..151692b 100644 --- a/src/template/commands/all.rs +++ b/src/template/commands/all.rs @@ -1,5 +1,5 @@ use crate::template::{all_days, run_multi::run_multi}; pub fn handle(is_release: bool, is_timed: bool) { - run_multi(all_days().collect(), is_release, is_timed); + run_multi(&all_days().collect(), is_release, is_timed); } diff --git a/src/template/commands/scaffold.rs b/src/template/commands/scaffold.rs index 8afdaed..4e7d7c0 100644 --- a/src/template/commands/scaffold.rs +++ b/src/template/commands/scaffold.rs @@ -65,5 +65,5 @@ pub fn handle(day: Day) { } println!("---"); - println!("🎄 Type `cargo solve {}` to run your solution.", day); + println!("🎄 Type `cargo solve {day}` to run your solution."); } diff --git a/src/template/commands/time.rs b/src/template/commands/time.rs index ce110ab..efbafbe 100644 --- a/src/template/commands/time.rs +++ b/src/template/commands/time.rs @@ -7,18 +7,21 @@ use crate::template::{all_days, readme_benchmarks, Day}; pub fn handle(day: Option, recreate_all: bool) { let stored_timings = Timings::read_from_file(); - let days_to_run = day.map(|day| HashSet::from([day])).unwrap_or_else(|| { - if recreate_all { - all_days().collect() - } else { - // when the `--all` flag is not set, filter out days that are fully benched. - all_days() - .filter(|day| !stored_timings.is_day_complete(day)) - .collect() - } - }); + let days_to_run = day.map_or_else( + || { + if recreate_all { + all_days().collect() + } else { + // when the `--all` flag is not set, filter out days that are fully benched. + all_days() + .filter(|day| !stored_timings.is_day_complete(*day)) + .collect() + } + }, + |day| HashSet::from([day]), + ); - let timings = run_multi(days_to_run, true, true).unwrap(); + let timings = run_multi(&days_to_run, true, true).unwrap(); let merged_timings = stored_timings.merge(&timings); merged_timings.store_file().unwrap(); @@ -26,7 +29,7 @@ pub fn handle(day: Option, recreate_all: bool) { println!(); match readme_benchmarks::update(merged_timings) { Ok(()) => { - println!("Stored updated benchmarks.") + println!("Stored updated benchmarks."); } Err(_) => { eprintln!("Failed to store updated benchmarks."); diff --git a/src/template/run_multi.rs b/src/template/run_multi.rs index 0fdf2d5..f0e2d03 100644 --- a/src/template/run_multi.rs +++ b/src/template/run_multi.rs @@ -7,7 +7,7 @@ use super::{ timings::{Timing, Timings}, }; -pub fn run_multi(days_to_run: HashSet, is_release: bool, is_timed: bool) -> Option { +pub fn run_multi(days_to_run: &HashSet, is_release: bool, is_timed: bool) -> Option { let mut timings: Vec = Vec::with_capacity(days_to_run.len()); all_days().for_each(|day| { diff --git a/src/template/timings.rs b/src/template/timings.rs index f7dc091..194464e 100644 --- a/src/template/timings.rs +++ b/src/template/timings.rs @@ -38,7 +38,7 @@ impl Timings { match s { Ok(timings) => timings, Err(e) => { - eprintln!("{}", e); + eprintln!("{e}"); Timings::default() } } @@ -67,10 +67,10 @@ impl Timings { self.data.iter().map(|x| x.total_nanos).sum::() / 1_000_000_f64 } - pub fn is_day_complete(&self, day: &Day) -> bool { + pub fn is_day_complete(&self, day: Day) -> bool { self.data .iter() - .any(|t| &t.day == day && t.part_1.is_some() && t.part_2.is_some()) + .any(|t| t.day == day && t.part_1.is_some() && t.part_2.is_some()) } }