Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address some clippy::pedantic warnings #55

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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