Skip to content

Commit

Permalink
chore: address some clippy::pedantic warnings (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
fspoettel authored Dec 11, 2023
1 parent 84208a6 commit f43530b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/template/commands/all.rs
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion src/template/commands/scaffold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
27 changes: 15 additions & 12 deletions src/template/commands/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ use crate::template::{all_days, readme_benchmarks, Day};
pub fn handle(day: Option<Day>, 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();

println!();
match readme_benchmarks::update(merged_timings) {
Ok(()) => {
println!("Stored updated benchmarks.")
println!("Stored updated benchmarks.");
}
Err(_) => {
eprintln!("Failed to store updated benchmarks.");
Expand Down
2 changes: 1 addition & 1 deletion src/template/run_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{
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());

all_days().for_each(|day| {
Expand Down
6 changes: 3 additions & 3 deletions src/template/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Timings {
match s {
Ok(timings) => timings,
Err(e) => {
eprintln!("{}", e);
eprintln!("{e}");
Timings::default()
}
}
Expand Down Expand Up @@ -67,10 +67,10 @@ impl Timings {
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
.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())
}
}

Expand Down

0 comments on commit f43530b

Please sign in to comment.