Skip to content

Commit 1c8ea27

Browse files
authored
Make the template pass cargo clippy by resolving warnings (#28)
* Resolve clippy::uninlined_format_args warnings * See https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
1 parent c8c3dc0 commit 1c8ea27

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

src/bin/download.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
let args = match parse_args() {
2323
Ok(args) => args,
2424
Err(e) => {
25-
eprintln!("Failed to process arguments: {}", e);
25+
eprintln!("Failed to process arguments: {e}");
2626
process::exit(1);
2727
}
2828
};
@@ -39,7 +39,7 @@ fn main() {
3939
}
4040
}
4141
Err(e) => {
42-
eprintln!("failed to spawn aoc-cli: {}", e);
42+
eprintln!("failed to spawn aoc-cli: {e}");
4343
process::exit(1);
4444
}
4545
}

src/bin/read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
let args = match parse_args() {
2323
Ok(args) => args,
2424
Err(e) => {
25-
eprintln!("Failed to process arguments: {}", e);
25+
eprintln!("Failed to process arguments: {e}");
2626
process::exit(1);
2727
}
2828
};
@@ -39,7 +39,7 @@ fn main() {
3939
}
4040
}
4141
Err(e) => {
42-
eprintln!("failed to spawn aoc-cli: {}", e);
42+
eprintln!("failed to spawn aoc-cli: {e}");
4343
process::exit(1);
4444
}
4545
}

src/bin/scaffold.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ fn main() {
6262
}
6363
};
6464

65-
let day_padded = format!("{:02}", day);
65+
let day_padded = format!("{day:02}");
6666

67-
let input_path = format!("src/inputs/{}.txt", day_padded);
68-
let example_path = format!("src/examples/{}.txt", day_padded);
69-
let module_path = format!("src/bin/{}.rs", day_padded);
67+
let input_path = format!("src/inputs/{day_padded}.txt");
68+
let example_path = format!("src/examples/{day_padded}.txt");
69+
let module_path = format!("src/bin/{day_padded}.rs");
7070

7171
let mut file = match safe_create_file(&module_path) {
7272
Ok(file) => file,
7373
Err(e) => {
74-
eprintln!("Failed to create module file: {}", e);
74+
eprintln!("Failed to create module file: {e}");
7575
process::exit(1);
7676
}
7777
};
@@ -81,7 +81,7 @@ fn main() {
8181
println!("Created module file \"{}\"", &module_path);
8282
}
8383
Err(e) => {
84-
eprintln!("Failed to write module contents: {}", e);
84+
eprintln!("Failed to write module contents: {e}");
8585
process::exit(1);
8686
}
8787
}
@@ -91,7 +91,7 @@ fn main() {
9191
println!("Created empty input file \"{}\"", &input_path);
9292
}
9393
Err(e) => {
94-
eprintln!("Failed to create input file: {}", e);
94+
eprintln!("Failed to create input file: {e}");
9595
process::exit(1);
9696
}
9797
}
@@ -101,7 +101,7 @@ fn main() {
101101
println!("Created empty example file \"{}\"", &example_path);
102102
}
103103
Err(e) => {
104-
eprintln!("Failed to create example file: {}", e);
104+
eprintln!("Failed to create example file: {e}");
105105
process::exit(1);
106106
}
107107
}

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! solve {
4444
pub fn read_file(folder: &str, day: u8) -> String {
4545
let cwd = env::current_dir().unwrap();
4646

47-
let filepath = cwd.join("src").join(folder).join(format!("{:02}.txt", day));
47+
let filepath = cwd.join("src").join(folder).join(format!("{day:02}.txt"));
4848

4949
let f = fs::read_to_string(filepath);
5050
f.expect("could not open input file")
@@ -197,13 +197,13 @@ pub mod aoc_cli {
197197
}
198198

199199
fn get_input_path(day: u8) -> String {
200-
let day_padded = format!("{:02}", day);
201-
format!("src/inputs/{}.txt", day_padded)
200+
let day_padded = format!("{day:02}");
201+
format!("src/inputs/{day_padded}.txt")
202202
}
203203

204204
fn get_puzzle_path(day: u8) -> String {
205-
let day_padded = format!("{:02}", day);
206-
format!("src/puzzles/{}.md", day_padded)
205+
let day_padded = format!("{day:02}");
206+
format!("src/puzzles/{day_padded}.md")
207207
}
208208

209209
fn build_args(command: &str, args: &[String], day: u8, year: Option<u16>) -> Vec<String> {

src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::process::Command;
88
fn main() {
99
let total: f64 = (1..=25)
1010
.map(|day| {
11-
let day = format!("{:02}", day);
11+
let day = format!("{day:02}");
1212

1313
let mut args = vec!["run", "--bin", &day];
1414
if cfg!(not(debug_assertions)) {
@@ -18,7 +18,7 @@ fn main() {
1818
let cmd = Command::new("cargo").args(&args).output().unwrap();
1919

2020
println!("----------");
21-
println!("{}| Day {} |{}", ANSI_BOLD, day, ANSI_RESET);
21+
println!("{ANSI_BOLD}| Day {day} |{ANSI_RESET}");
2222
println!("----------");
2323

2424
let output = String::from_utf8(cmd.stdout).unwrap();
@@ -41,8 +41,5 @@ fn main() {
4141
})
4242
.sum();
4343

44-
println!(
45-
"{}Total:{} {}{:.2}ms{}",
46-
ANSI_BOLD, ANSI_RESET, ANSI_ITALIC, total, ANSI_RESET
47-
);
44+
println!("{ANSI_BOLD}Total:{ANSI_RESET} {ANSI_ITALIC}{total:.2}ms{ANSI_RESET}");
4845
}

0 commit comments

Comments
 (0)