chore: address some clippy::pedantic warnings (#55)

This commit is contained in:
Felix Spöttel 2023-12-11 09:43:59 +01:00 committed by GitHub
parent 84208a663a
commit f43530b297
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 18 deletions

View file

@ -1,5 +1,5 @@
use crate::template::{all_days, run_multi::run_multi}; use crate::template::{all_days, run_multi::run_multi};
pub fn handle(is_release: bool, is_timed: bool) { 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);
} }

View file

@ -65,5 +65,5 @@ pub fn handle(day: Day) {
} }
println!("---"); println!("---");
println!("🎄 Type `cargo solve {}` to run your solution.", day); println!("🎄 Type `cargo solve {day}` to run your solution.");
} }

View file

@ -7,18 +7,21 @@ use crate::template::{all_days, readme_benchmarks, Day};
pub fn handle(day: Option<Day>, recreate_all: bool) { pub fn handle(day: Option<Day>, recreate_all: bool) {
let stored_timings = Timings::read_from_file(); let stored_timings = Timings::read_from_file();
let days_to_run = day.map(|day| HashSet::from([day])).unwrap_or_else(|| { let days_to_run = day.map_or_else(
if recreate_all { || {
all_days().collect() if recreate_all {
} else { all_days().collect()
// when the `--all` flag is not set, filter out days that are fully benched. } else {
all_days() // when the `--all` flag is not set, filter out days that are fully benched.
.filter(|day| !stored_timings.is_day_complete(day)) all_days()
.collect() .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); let merged_timings = stored_timings.merge(&timings);
merged_timings.store_file().unwrap(); merged_timings.store_file().unwrap();
@ -26,7 +29,7 @@ pub fn handle(day: Option<Day>, recreate_all: bool) {
println!(); println!();
match readme_benchmarks::update(merged_timings) { match readme_benchmarks::update(merged_timings) {
Ok(()) => { Ok(()) => {
println!("Stored updated benchmarks.") println!("Stored updated benchmarks.");
} }
Err(_) => { Err(_) => {
eprintln!("Failed to store updated benchmarks."); eprintln!("Failed to store updated benchmarks.");

View file

@ -7,7 +7,7 @@ use super::{
timings::{Timing, Timings}, timings::{Timing, Timings},
}; };
pub fn run_multi(days_to_run: HashSet<Day>, is_release: bool, is_timed: bool) -> Option<Timings> { pub fn run_multi(days_to_run: &HashSet<Day>, is_release: bool, is_timed: bool) -> Option<Timings> {
let mut timings: Vec<Timing> = Vec::with_capacity(days_to_run.len()); let mut timings: Vec<Timing> = Vec::with_capacity(days_to_run.len());
all_days().for_each(|day| { all_days().for_each(|day| {

View file

@ -38,7 +38,7 @@ impl Timings {
match s { match s {
Ok(timings) => timings, Ok(timings) => timings,
Err(e) => { Err(e) => {
eprintln!("{}", e); eprintln!("{e}");
Timings::default() Timings::default()
} }
} }
@ -67,10 +67,10 @@ impl Timings {
self.data.iter().map(|x| x.total_nanos).sum::<f64>() / 1_000_000_f64 self.data.iter().map(|x| x.total_nanos).sum::<f64>() / 1_000_000_f64
} }
pub fn is_day_complete(&self, day: &Day) -> bool { pub fn is_day_complete(&self, day: Day) -> bool {
self.data self.data
.iter() .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())
} }
} }