Skip to content

Commit f892f28

Browse files
authored
Fix uninlined_format_args clippy (#7)
1 parent 42f2436 commit f892f28

9 files changed

Lines changed: 47 additions & 54 deletions

File tree

src/board.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ mod tests {
407407
let board = board_result.unwrap();
408408
assert_eq!(board.size(), 4);
409409
assert_eq!(board.square_count(), 16);
410-
assert_eq!(format!("{}", board), board_str);
410+
assert_eq!(format!("{board}"), board_str);
411411
}
412412

413413
#[test]

src/datastructure.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ mod tests {
411411
assert!(!sqs.is_empty());
412412
assert!(sqs.contains(&SquareColor::Black));
413413
assert!(!sqs.contains(&SquareColor::Red));
414-
assert_eq!(format!("{}", sqs), "[Black, Blue, White]");
414+
assert_eq!(format!("{sqs}"), "[Black, Blue, White]");
415415
}
416416

417417
#[test]
@@ -422,7 +422,7 @@ mod tests {
422422
assert!(ls.contains(&0));
423423
assert!(!ls.contains(&1));
424424
assert_eq!(ls.iter().collect::<Vec<_>>(), vec![0, 2, 5]);
425-
assert_eq!(format!("{}", ls), "[0, 2, 5]");
425+
assert_eq!(format!("{ls}"), "[0, 2, 5]");
426426
}
427427

428428
#[test]
@@ -433,7 +433,7 @@ mod tests {
433433
assert!(cs.contains(&(0, 0)));
434434
assert!(!cs.contains(&(5, 5)));
435435
assert_eq!(cs.iter().collect::<Vec<_>>(), vec![(0, 0), (1, 1), (2, 4)]);
436-
assert_eq!(format!("{}", cs), "[(0, 0), (1, 1), (2, 4)]");
436+
assert_eq!(format!("{cs}"), "[(0, 0), (1, 1), (2, 4)]");
437437
cs.extend([(5, 5)]);
438438
assert!(cs.contains(&(5, 5)));
439439
}

src/file.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ impl QueensFile {
9393
/// a QueensFile from it.
9494
pub fn try_from_text_file(path: &std::path::PathBuf) -> Result<Self> {
9595
let content = std::fs::read_to_string(path)
96-
.with_context(|| format!("Could not read file `{:?}`", path))?;
96+
.with_context(|| format!("Could not read file `{path:?}`"))?;
9797

9898
QueensFile::from_str(&content)
99-
.with_context(|| format!("Failed to create board from text file at {:?}", path))
99+
.with_context(|| format!("Failed to create board from text file at {path:?}"))
100100
}
101101

102102
/// This reads the given path as an image file and attempts to return
@@ -105,7 +105,7 @@ impl QueensFile {
105105
let rgb_image = ImageReader::open(path)?.decode()?.to_rgb8();
106106

107107
analyze_grid_image(&rgb_image)
108-
.with_context(|| format!("Failed to create board from image at {:?}", path))
108+
.with_context(|| format!("Failed to create board from image at {path:?}"))
109109
}
110110
}
111111

@@ -154,7 +154,7 @@ mod tests {
154154
fn input_squares_display() -> Result<()> {
155155
let input_str = "Qxxx\nxx..\nx...\nx...";
156156
let input_squares = InputSquares::from_str(input_str)?;
157-
assert_eq!(format!("{}", input_squares), input_str.replace(".", " "));
157+
assert_eq!(format!("{input_squares}"), input_str.replace(".", " "));
158158
Ok(())
159159
}
160160

src/heuristic.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ pub fn next_heuristic<'h>(
7777
heuristics: &'h [Box<dyn Heuristic>],
7878
) -> Option<&'h dyn Heuristic> {
7979
debug!(
80-
"Generating next heuristic with {:?} strategy",
81-
solve_strategy
80+
"Generating next heuristic with {solve_strategy:?} strategy"
8281
);
8382
let h = match solve_strategy {
8483
SolveStrategy::Short => heuristics
@@ -127,7 +126,7 @@ pub fn all_heuristics(board: &Board) -> Vec<Box<dyn Heuristic>> {
127126
v.extend(board.all_colors().iter().map(|color| {
128127
Box::new(LastSquareAvailable {
129128
coords: board.coords_for_color(color),
130-
desc: format!("'{:?}' Color", color),
129+
desc: format!("'{color:?}' Color"),
131130
}) as _
132131
}));
133132
v.extend((0..board.size()).map(|r| {
@@ -157,7 +156,7 @@ pub fn all_heuristics(board: &Board) -> Vec<Box<dyn Heuristic>> {
157156
v.extend(board.all_colors().into_iter().map(|color| {
158157
Box::new(AllPossibilitiesEliminateSquare {
159158
coords: board.coords_for_color(color),
160-
desc: format!("'{:?}' Color", color),
159+
desc: format!("'{color:?}' Color"),
161160
}) as _
162161
}));
163162

@@ -186,7 +185,7 @@ pub fn all_heuristics(board: &Board) -> Vec<Box<dyn Heuristic>> {
186185
.filter(|cc| !cc.is_empty())
187186
.map(|cc| {
188187
Box::new(NColorsOnlyAppearInNLines {
189-
color_desc: format!("{:?}", cc),
188+
color_desc: format!("{cc:?}"),
190189
colors: SquareColorSet::from_iter(cc.into_iter().copied()),
191190
liner: |coord| coord.0,
192191
liner_desc: "rows".to_string(),
@@ -201,7 +200,7 @@ pub fn all_heuristics(board: &Board) -> Vec<Box<dyn Heuristic>> {
201200
.filter(|cc| !cc.is_empty())
202201
.map(|cc| {
203202
Box::new(NColorsOnlyAppearInNLines {
204-
color_desc: format!("{:?}", cc),
203+
color_desc: format!("{cc:?}"),
205204
colors: SquareColorSet::from_iter(cc.into_iter().copied()),
206205
liner: |coord| coord.1,
207206
liner_desc: "cols".to_string(),
@@ -223,22 +222,22 @@ impl Heuristic for LastSquareAvailable {
223222
self.coords
224223
}
225224
fn changes(&self, solve_state: &SolveState) -> Option<Changes> {
226-
trace!("Heuristic Start: LastSquareAvailable {:?}", self);
225+
trace!("Heuristic Start: LastSquareAvailable {self:?}");
227226
let last_empty_coord = self
228227
.coords
229228
.iter()
230229
.filter(|&c| solve_state.square(&c).is_none())
231230
.exactly_one()
232231
.ok();
233232
let queen = last_empty_coord?;
234-
trace!("Heuristic Success: LastSquareAvailable {:?}", self);
233+
trace!("Heuristic Success: LastSquareAvailable {self:?}");
235234
let x = solve_state
236235
.board
237236
.queen_borders(&queen)
238237
.iter()
239238
.filter(|&coord| solve_state.square(&coord).is_none())
240239
.collect::<CoordSet>();
241-
trace!("Heuristic Return: LastSquareAvailable {:?}", self);
240+
trace!("Heuristic Return: LastSquareAvailable {self:?}");
242241
Some(Changes::AddQueen { queen, x })
243242
}
244243

@@ -265,8 +264,7 @@ impl Heuristic for AllPossibilitiesEliminateSquare {
265264
}
266265
fn changes(&self, solve_state: &SolveState) -> Option<Changes> {
267266
trace!(
268-
"Heuristic Start: AllPossibilitiesEliminateSquare {:?}",
269-
self
267+
"Heuristic Start: AllPossibilitiesEliminateSquare {self:?}"
270268
);
271269
let x = self
272270
.coords
@@ -282,8 +280,7 @@ impl Heuristic for AllPossibilitiesEliminateSquare {
282280
None
283281
} else {
284282
trace!(
285-
"Heuristic Success/Return: AllPossibilitiesEliminateSquare {:?}",
286-
self
283+
"Heuristic Success/Return: AllPossibilitiesEliminateSquare {self:?}"
287284
);
288285
Some(Changes::AddX { x })
289286
}
@@ -312,14 +309,14 @@ impl Heuristic for NLinesContainOnlyNColors {
312309
.collect()
313310
}
314311
fn changes(&self, solve_state: &SolveState) -> Option<Changes> {
315-
trace!("Heuristic Start: NLinesContainOnlyNColors {:?}", self);
312+
trace!("Heuristic Start: NLinesContainOnlyNColors {self:?}");
316313
if self
317314
.lines
318315
.iter()
319316
.flatten()
320317
.any(|coord| solve_state.square(&coord) == Some(SquareVal::Queen))
321318
{
322-
trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self);
319+
trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}");
323320
return None;
324321
}
325322
let coords = CoordSet::from_iter(
@@ -331,10 +328,10 @@ impl Heuristic for NLinesContainOnlyNColors {
331328
let colors_set =
332329
SquareColorSet::from_iter(coords.iter().map(|coord| solve_state.board.color(&coord)));
333330
if colors_set.len() > self.lines.len() {
334-
trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self);
331+
trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}");
335332
return None;
336333
}
337-
trace!("Heuristic Success: NLinesContainOnlyNColors {:?}", self);
334+
trace!("Heuristic Success: NLinesContainOnlyNColors {self:?}");
338335
let x = solve_state
339336
.board
340337
.all_coords()
@@ -344,10 +341,10 @@ impl Heuristic for NLinesContainOnlyNColors {
344341
.filter(|coord| solve_state.square(coord).is_none())
345342
.collect::<CoordSet>();
346343
if x.is_empty() {
347-
trace!("Heuristic No-op: NLinesContainOnlyNColors {:?}", self);
344+
trace!("Heuristic No-op: NLinesContainOnlyNColors {self:?}");
348345
None
349346
} else {
350-
trace!("Heuristic Return: NLinesContainOnlyNColors {:?}", self);
347+
trace!("Heuristic Return: NLinesContainOnlyNColors {self:?}");
351348
Some(Changes::AddX { x })
352349
}
353350
}
@@ -380,15 +377,15 @@ impl Heuristic for NColorsOnlyAppearInNLines {
380377
.collect()
381378
}
382379
fn changes(&self, solve_state: &SolveState) -> Option<Changes> {
383-
trace!("Heuristic Start: NLinesContainOnlyNColors {:?}", self);
380+
trace!("Heuristic Start: NLinesContainOnlyNColors {self:?}");
384381
if solve_state
385382
.board
386383
.all_coords()
387384
.iter()
388385
.filter(|coord| self.colors.contains(&solve_state.board.color(coord)))
389386
.any(|coord| solve_state.square(&coord) == Some(SquareVal::Queen))
390387
{
391-
trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self);
388+
trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}");
392389
return None;
393390
}
394391
let coords = solve_state.board.all_coords();
@@ -399,10 +396,10 @@ impl Heuristic for NColorsOnlyAppearInNLines {
399396
.map(self.liner);
400397
let lines_set = LineSet::from_iter(lines);
401398
if lines_set.len() > self.colors.len() {
402-
trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self);
399+
trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}");
403400
return None;
404401
}
405-
trace!("Heuristic Success: NLinesContainOnlyNColors {:?}", self);
402+
trace!("Heuristic Success: NLinesContainOnlyNColors {self:?}");
406403
let x = solve_state
407404
.board
408405
.all_coords()
@@ -412,10 +409,10 @@ impl Heuristic for NColorsOnlyAppearInNLines {
412409
.filter(|coord| solve_state.square(coord).is_none())
413410
.collect::<CoordSet>();
414411
if x.is_empty() {
415-
trace!("Heuristic No-op: NLinesContainOnlyNColors {:?}", self);
412+
trace!("Heuristic No-op: NLinesContainOnlyNColors {self:?}");
416413
None
417414
} else {
418-
trace!("Heuristic Return: NLinesContainOnlyNColors {:?}", self);
415+
trace!("Heuristic Return: NLinesContainOnlyNColors {self:?}");
419416
Some(Changes::AddX { x })
420417
}
421418
}

src/image.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const X_OTHER_RATIO: f32 = 0.01;
8484
/// # }
8585
/// ```
8686
pub fn analyze_grid_image(img: &RgbImage) -> Result<QueensFile> {
87-
trace!("Analyze grid image start: {:?}", img);
87+
trace!("Analyze grid image start: {img:?}");
8888
let width_ranges = find_grid_ranges(img, 0..img.width(), true);
8989
ensure!(
9090
width_ranges.len() >= 4,
@@ -110,8 +110,7 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result<QueensFile> {
110110
let mut square_values = Vec::with_capacity(board_size * board_size);
111111

112112
trace!(
113-
"Analyze grid image ranges found: {:?} {:?}",
114-
width_ranges, height_ranges
113+
"Analyze grid image ranges found: {width_ranges:?} {height_ranges:?}"
115114
);
116115
for (height_range, width_range) in iproduct!(height_ranges, width_ranges) {
117116
let view = img.view(
@@ -128,8 +127,7 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result<QueensFile> {
128127
)
129128
})?;
130129
trace!(
131-
"Analyze grid image color: for height {:?} width {:?} got dominant color {:?}",
132-
height_range, width_range, rgb_color
130+
"Analyze grid image color: for height {height_range:?} width {width_range:?} got dominant color {rgb_color:?}"
133131
);
134132
all_rgb_colors.push(rgb_color);
135133

@@ -140,8 +138,7 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result<QueensFile> {
140138
_ => None,
141139
};
142140
trace!(
143-
"Analyze grid image ratio: For height {:?} width {:?} got ratio {:?} and value {:?}",
144-
height_range, width_range, other_ratio, square_val
141+
"Analyze grid image ratio: For height {height_range:?} width {width_range:?} got ratio {other_ratio:?} and value {square_val:?}"
145142
);
146143
square_values.push(square_val);
147144
}
@@ -175,8 +172,8 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result<QueensFile> {
175172
let board = Board::new(board_size, colors);
176173
let squares = InputSquares::from(square_values);
177174
trace!("Analyze grid image done.");
178-
trace!("Board:\n{}", board);
179-
trace!("Squares:\n{}", squares);
175+
trace!("Board:\n{board}");
176+
trace!("Squares:\n{squares}");
180177
Ok(QueensFile {
181178
board,
182179
squares: Some(squares),

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn profile(path_args: &PathCli, solve_args: &SolveCli, iterations: &usize) -> Re
371371
solve_iter(solve_state, solve_args.strategy, &heuristics).for_each(drop);
372372
}
373373
let elapsed = start_time.elapsed();
374-
println!("{} iterations completed in {:?}", iterations, elapsed);
374+
println!("{iterations} iterations completed in {elapsed:?}");
375375
Ok(())
376376
}
377377

src/share.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ pub fn generate_share_content(
5858
.collect::<Vec<_>>();
5959

6060
let puzzle_name = if puzzle_name.chars().all(char::is_numeric) {
61-
format!("#{}", puzzle_name)
61+
format!("#{puzzle_name}")
6262
} else {
6363
puzzle_name.to_string()
6464
};
6565

6666
let mut output = String::new();
6767
output.push_str(&format!(
68-
"QSolve {} | {:?} and flawless\n",
69-
puzzle_name, elapsed
68+
"QSolve {puzzle_name} | {elapsed:?} and flawless\n"
7069
));
7170
output.push_str(&format!(
7271
"First \u{1f451}s: {}\n",

src/solvestate.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub enum SolveStrategy {
9797

9898
impl Display for SolveStrategy {
9999
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
100-
write!(f, "{:?}", self)
100+
write!(f, "{self:?}")
101101
}
102102
}
103103

@@ -174,7 +174,7 @@ impl<'a> From<&'a QueensFile> for SolveState<'a> {
174174
solve_state.apply_changes(&Changes::AddQueen { queen, x });
175175
}
176176

177-
trace!("From<QueensFile> for SolveState done:\n{}", solve_state);
177+
trace!("From<QueensFile> for SolveState done:\n{solve_state}");
178178

179179
solve_state
180180
}
@@ -384,13 +384,13 @@ mod tests {
384384
fn solvestate_from_queens_file() {
385385
let board_str = "wwww\nkkkk\nrrrr\nbbbb";
386386
let squares_str = "Qxxx\nxx..\nx...\nx. _";
387-
let qf_str = format!("{}\n\n{}", board_str, squares_str);
387+
let qf_str = format!("{board_str}\n\n{squares_str}");
388388
let qf = QueensFile::from_str(&qf_str).unwrap();
389389
let ss = SolveState::from(&qf);
390390
assert!(ss.is_valid());
391391

392392
assert_eq!(
393-
format!("{}", ss),
393+
format!("{ss}"),
394394
qf_str.replace(".", " ").replace("_", " ")
395395
);
396396
}
@@ -399,7 +399,7 @@ mod tests {
399399
fn solvestate_ansi_string() {
400400
let board_str = "wwww\nkkkk\nrrrr\nbbbb";
401401
let squares_str = "Qxxx\nxx..\nx...\nx. _";
402-
let qf_str = format!("{}\n\n{}", board_str, squares_str);
402+
let qf_str = format!("{board_str}\n\n{squares_str}");
403403
let qf = QueensFile::from_str(&qf_str).unwrap();
404404
let ss = SolveState::from(&qf);
405405
assert!(ss.is_valid());
@@ -417,7 +417,7 @@ mod tests {
417417
fn solvestate_ansi_string_highlighted() {
418418
let board_str = "wwww\nkkkk\nrrrr\nbbbb";
419419
let squares_str = "Qxxx\nxx..\nx...\nx. _";
420-
let qf_str = format!("{}\n\n{}", board_str, squares_str);
420+
let qf_str = format!("{board_str}\n\n{squares_str}");
421421
let qf = QueensFile::from_str(&qf_str).unwrap();
422422
let ss = SolveState::from(&qf);
423423
assert!(ss.is_valid());

src/squarecolor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl Display for SquareColor {
142142
SquareColor::BrightCyan => 'C',
143143
SquareColor::BrightWhite => 'W',
144144
};
145-
write!(f, "{}", c)
145+
write!(f, "{c}")
146146
}
147147
}
148148

@@ -188,7 +188,7 @@ mod tests {
188188
#[test]
189189
fn squarecolor_char_roundtrip() {
190190
for sc in ALL_SQUARE_COLORS {
191-
let c = format!("{}", sc).chars().next().unwrap();
191+
let c = format!("{sc}").chars().next().unwrap();
192192
assert_eq!(SquareColor::try_from(c).unwrap(), sc)
193193
}
194194
}

0 commit comments

Comments
 (0)