diff --git a/src/board.rs b/src/board.rs index a2b2a17..95b918e 100644 --- a/src/board.rs +++ b/src/board.rs @@ -407,7 +407,7 @@ mod tests { let board = board_result.unwrap(); assert_eq!(board.size(), 4); assert_eq!(board.square_count(), 16); - assert_eq!(format!("{}", board), board_str); + assert_eq!(format!("{board}"), board_str); } #[test] diff --git a/src/datastructure.rs b/src/datastructure.rs index 85216ee..71466ad 100644 --- a/src/datastructure.rs +++ b/src/datastructure.rs @@ -411,7 +411,7 @@ mod tests { assert!(!sqs.is_empty()); assert!(sqs.contains(&SquareColor::Black)); assert!(!sqs.contains(&SquareColor::Red)); - assert_eq!(format!("{}", sqs), "[Black, Blue, White]"); + assert_eq!(format!("{sqs}"), "[Black, Blue, White]"); } #[test] @@ -422,7 +422,7 @@ mod tests { assert!(ls.contains(&0)); assert!(!ls.contains(&1)); assert_eq!(ls.iter().collect::>(), vec![0, 2, 5]); - assert_eq!(format!("{}", ls), "[0, 2, 5]"); + assert_eq!(format!("{ls}"), "[0, 2, 5]"); } #[test] @@ -433,7 +433,7 @@ mod tests { assert!(cs.contains(&(0, 0))); assert!(!cs.contains(&(5, 5))); assert_eq!(cs.iter().collect::>(), vec![(0, 0), (1, 1), (2, 4)]); - assert_eq!(format!("{}", cs), "[(0, 0), (1, 1), (2, 4)]"); + assert_eq!(format!("{cs}"), "[(0, 0), (1, 1), (2, 4)]"); cs.extend([(5, 5)]); assert!(cs.contains(&(5, 5))); } diff --git a/src/file.rs b/src/file.rs index 9ab70db..5dcf5f2 100644 --- a/src/file.rs +++ b/src/file.rs @@ -93,10 +93,10 @@ impl QueensFile { /// a QueensFile from it. pub fn try_from_text_file(path: &std::path::PathBuf) -> Result { let content = std::fs::read_to_string(path) - .with_context(|| format!("Could not read file `{:?}`", path))?; + .with_context(|| format!("Could not read file `{path:?}`"))?; QueensFile::from_str(&content) - .with_context(|| format!("Failed to create board from text file at {:?}", path)) + .with_context(|| format!("Failed to create board from text file at {path:?}")) } /// This reads the given path as an image file and attempts to return @@ -105,7 +105,7 @@ impl QueensFile { let rgb_image = ImageReader::open(path)?.decode()?.to_rgb8(); analyze_grid_image(&rgb_image) - .with_context(|| format!("Failed to create board from image at {:?}", path)) + .with_context(|| format!("Failed to create board from image at {path:?}")) } } @@ -154,7 +154,7 @@ mod tests { fn input_squares_display() -> Result<()> { let input_str = "Qxxx\nxx..\nx...\nx..."; let input_squares = InputSquares::from_str(input_str)?; - assert_eq!(format!("{}", input_squares), input_str.replace(".", " ")); + assert_eq!(format!("{input_squares}"), input_str.replace(".", " ")); Ok(()) } diff --git a/src/heuristic.rs b/src/heuristic.rs index a79c678..808aaf6 100644 --- a/src/heuristic.rs +++ b/src/heuristic.rs @@ -77,8 +77,7 @@ pub fn next_heuristic<'h>( heuristics: &'h [Box], ) -> Option<&'h dyn Heuristic> { debug!( - "Generating next heuristic with {:?} strategy", - solve_strategy + "Generating next heuristic with {solve_strategy:?} strategy" ); let h = match solve_strategy { SolveStrategy::Short => heuristics @@ -127,7 +126,7 @@ pub fn all_heuristics(board: &Board) -> Vec> { v.extend(board.all_colors().iter().map(|color| { Box::new(LastSquareAvailable { coords: board.coords_for_color(color), - desc: format!("'{:?}' Color", color), + desc: format!("'{color:?}' Color"), }) as _ })); v.extend((0..board.size()).map(|r| { @@ -157,7 +156,7 @@ pub fn all_heuristics(board: &Board) -> Vec> { v.extend(board.all_colors().into_iter().map(|color| { Box::new(AllPossibilitiesEliminateSquare { coords: board.coords_for_color(color), - desc: format!("'{:?}' Color", color), + desc: format!("'{color:?}' Color"), }) as _ })); @@ -186,7 +185,7 @@ pub fn all_heuristics(board: &Board) -> Vec> { .filter(|cc| !cc.is_empty()) .map(|cc| { Box::new(NColorsOnlyAppearInNLines { - color_desc: format!("{:?}", cc), + color_desc: format!("{cc:?}"), colors: SquareColorSet::from_iter(cc.into_iter().copied()), liner: |coord| coord.0, liner_desc: "rows".to_string(), @@ -201,7 +200,7 @@ pub fn all_heuristics(board: &Board) -> Vec> { .filter(|cc| !cc.is_empty()) .map(|cc| { Box::new(NColorsOnlyAppearInNLines { - color_desc: format!("{:?}", cc), + color_desc: format!("{cc:?}"), colors: SquareColorSet::from_iter(cc.into_iter().copied()), liner: |coord| coord.1, liner_desc: "cols".to_string(), @@ -223,7 +222,7 @@ impl Heuristic for LastSquareAvailable { self.coords } fn changes(&self, solve_state: &SolveState) -> Option { - trace!("Heuristic Start: LastSquareAvailable {:?}", self); + trace!("Heuristic Start: LastSquareAvailable {self:?}"); let last_empty_coord = self .coords .iter() @@ -231,14 +230,14 @@ impl Heuristic for LastSquareAvailable { .exactly_one() .ok(); let queen = last_empty_coord?; - trace!("Heuristic Success: LastSquareAvailable {:?}", self); + trace!("Heuristic Success: LastSquareAvailable {self:?}"); let x = solve_state .board .queen_borders(&queen) .iter() .filter(|&coord| solve_state.square(&coord).is_none()) .collect::(); - trace!("Heuristic Return: LastSquareAvailable {:?}", self); + trace!("Heuristic Return: LastSquareAvailable {self:?}"); Some(Changes::AddQueen { queen, x }) } @@ -265,8 +264,7 @@ impl Heuristic for AllPossibilitiesEliminateSquare { } fn changes(&self, solve_state: &SolveState) -> Option { trace!( - "Heuristic Start: AllPossibilitiesEliminateSquare {:?}", - self + "Heuristic Start: AllPossibilitiesEliminateSquare {self:?}" ); let x = self .coords @@ -282,8 +280,7 @@ impl Heuristic for AllPossibilitiesEliminateSquare { None } else { trace!( - "Heuristic Success/Return: AllPossibilitiesEliminateSquare {:?}", - self + "Heuristic Success/Return: AllPossibilitiesEliminateSquare {self:?}" ); Some(Changes::AddX { x }) } @@ -312,14 +309,14 @@ impl Heuristic for NLinesContainOnlyNColors { .collect() } fn changes(&self, solve_state: &SolveState) -> Option { - trace!("Heuristic Start: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Start: NLinesContainOnlyNColors {self:?}"); if self .lines .iter() .flatten() .any(|coord| solve_state.square(&coord) == Some(SquareVal::Queen)) { - trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}"); return None; } let coords = CoordSet::from_iter( @@ -331,10 +328,10 @@ impl Heuristic for NLinesContainOnlyNColors { let colors_set = SquareColorSet::from_iter(coords.iter().map(|coord| solve_state.board.color(&coord))); if colors_set.len() > self.lines.len() { - trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}"); return None; } - trace!("Heuristic Success: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Success: NLinesContainOnlyNColors {self:?}"); let x = solve_state .board .all_coords() @@ -344,10 +341,10 @@ impl Heuristic for NLinesContainOnlyNColors { .filter(|coord| solve_state.square(coord).is_none()) .collect::(); if x.is_empty() { - trace!("Heuristic No-op: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic No-op: NLinesContainOnlyNColors {self:?}"); None } else { - trace!("Heuristic Return: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Return: NLinesContainOnlyNColors {self:?}"); Some(Changes::AddX { x }) } } @@ -380,7 +377,7 @@ impl Heuristic for NColorsOnlyAppearInNLines { .collect() } fn changes(&self, solve_state: &SolveState) -> Option { - trace!("Heuristic Start: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Start: NLinesContainOnlyNColors {self:?}"); if solve_state .board .all_coords() @@ -388,7 +385,7 @@ impl Heuristic for NColorsOnlyAppearInNLines { .filter(|coord| self.colors.contains(&solve_state.board.color(coord))) .any(|coord| solve_state.square(&coord) == Some(SquareVal::Queen)) { - trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}"); return None; } let coords = solve_state.board.all_coords(); @@ -399,10 +396,10 @@ impl Heuristic for NColorsOnlyAppearInNLines { .map(self.liner); let lines_set = LineSet::from_iter(lines); if lines_set.len() > self.colors.len() { - trace!("Heuristic Invalid: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Invalid: NLinesContainOnlyNColors {self:?}"); return None; } - trace!("Heuristic Success: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Success: NLinesContainOnlyNColors {self:?}"); let x = solve_state .board .all_coords() @@ -412,10 +409,10 @@ impl Heuristic for NColorsOnlyAppearInNLines { .filter(|coord| solve_state.square(coord).is_none()) .collect::(); if x.is_empty() { - trace!("Heuristic No-op: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic No-op: NLinesContainOnlyNColors {self:?}"); None } else { - trace!("Heuristic Return: NLinesContainOnlyNColors {:?}", self); + trace!("Heuristic Return: NLinesContainOnlyNColors {self:?}"); Some(Changes::AddX { x }) } } diff --git a/src/image.rs b/src/image.rs index 0725416..fb1f96a 100644 --- a/src/image.rs +++ b/src/image.rs @@ -84,7 +84,7 @@ const X_OTHER_RATIO: f32 = 0.01; /// # } /// ``` pub fn analyze_grid_image(img: &RgbImage) -> Result { - trace!("Analyze grid image start: {:?}", img); + trace!("Analyze grid image start: {img:?}"); let width_ranges = find_grid_ranges(img, 0..img.width(), true); ensure!( width_ranges.len() >= 4, @@ -110,8 +110,7 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result { let mut square_values = Vec::with_capacity(board_size * board_size); trace!( - "Analyze grid image ranges found: {:?} {:?}", - width_ranges, height_ranges + "Analyze grid image ranges found: {width_ranges:?} {height_ranges:?}" ); for (height_range, width_range) in iproduct!(height_ranges, width_ranges) { let view = img.view( @@ -128,8 +127,7 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result { ) })?; trace!( - "Analyze grid image color: for height {:?} width {:?} got dominant color {:?}", - height_range, width_range, rgb_color + "Analyze grid image color: for height {height_range:?} width {width_range:?} got dominant color {rgb_color:?}" ); all_rgb_colors.push(rgb_color); @@ -140,8 +138,7 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result { _ => None, }; trace!( - "Analyze grid image ratio: For height {:?} width {:?} got ratio {:?} and value {:?}", - height_range, width_range, other_ratio, square_val + "Analyze grid image ratio: For height {height_range:?} width {width_range:?} got ratio {other_ratio:?} and value {square_val:?}" ); square_values.push(square_val); } @@ -175,8 +172,8 @@ pub fn analyze_grid_image(img: &RgbImage) -> Result { let board = Board::new(board_size, colors); let squares = InputSquares::from(square_values); trace!("Analyze grid image done."); - trace!("Board:\n{}", board); - trace!("Squares:\n{}", squares); + trace!("Board:\n{board}"); + trace!("Squares:\n{squares}"); Ok(QueensFile { board, squares: Some(squares), diff --git a/src/main.rs b/src/main.rs index 9e17608..6ea9df1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -371,7 +371,7 @@ fn profile(path_args: &PathCli, solve_args: &SolveCli, iterations: &usize) -> Re solve_iter(solve_state, solve_args.strategy, &heuristics).for_each(drop); } let elapsed = start_time.elapsed(); - println!("{} iterations completed in {:?}", iterations, elapsed); + println!("{iterations} iterations completed in {elapsed:?}"); Ok(()) } diff --git a/src/share.rs b/src/share.rs index 3ab0410..7b534fc 100644 --- a/src/share.rs +++ b/src/share.rs @@ -58,15 +58,14 @@ pub fn generate_share_content( .collect::>(); let puzzle_name = if puzzle_name.chars().all(char::is_numeric) { - format!("#{}", puzzle_name) + format!("#{puzzle_name}") } else { puzzle_name.to_string() }; let mut output = String::new(); output.push_str(&format!( - "QSolve {} | {:?} and flawless\n", - puzzle_name, elapsed + "QSolve {puzzle_name} | {elapsed:?} and flawless\n" )); output.push_str(&format!( "First \u{1f451}s: {}\n", diff --git a/src/solvestate.rs b/src/solvestate.rs index 115ab74..4c024e3 100644 --- a/src/solvestate.rs +++ b/src/solvestate.rs @@ -97,7 +97,7 @@ pub enum SolveStrategy { impl Display for SolveStrategy { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self) + write!(f, "{self:?}") } } @@ -174,7 +174,7 @@ impl<'a> From<&'a QueensFile> for SolveState<'a> { solve_state.apply_changes(&Changes::AddQueen { queen, x }); } - trace!("From for SolveState done:\n{}", solve_state); + trace!("From for SolveState done:\n{solve_state}"); solve_state } @@ -384,13 +384,13 @@ mod tests { fn solvestate_from_queens_file() { let board_str = "wwww\nkkkk\nrrrr\nbbbb"; let squares_str = "Qxxx\nxx..\nx...\nx. _"; - let qf_str = format!("{}\n\n{}", board_str, squares_str); + let qf_str = format!("{board_str}\n\n{squares_str}"); let qf = QueensFile::from_str(&qf_str).unwrap(); let ss = SolveState::from(&qf); assert!(ss.is_valid()); assert_eq!( - format!("{}", ss), + format!("{ss}"), qf_str.replace(".", " ").replace("_", " ") ); } @@ -399,7 +399,7 @@ mod tests { fn solvestate_ansi_string() { let board_str = "wwww\nkkkk\nrrrr\nbbbb"; let squares_str = "Qxxx\nxx..\nx...\nx. _"; - let qf_str = format!("{}\n\n{}", board_str, squares_str); + let qf_str = format!("{board_str}\n\n{squares_str}"); let qf = QueensFile::from_str(&qf_str).unwrap(); let ss = SolveState::from(&qf); assert!(ss.is_valid()); @@ -417,7 +417,7 @@ mod tests { fn solvestate_ansi_string_highlighted() { let board_str = "wwww\nkkkk\nrrrr\nbbbb"; let squares_str = "Qxxx\nxx..\nx...\nx. _"; - let qf_str = format!("{}\n\n{}", board_str, squares_str); + let qf_str = format!("{board_str}\n\n{squares_str}"); let qf = QueensFile::from_str(&qf_str).unwrap(); let ss = SolveState::from(&qf); assert!(ss.is_valid()); diff --git a/src/squarecolor.rs b/src/squarecolor.rs index fe9ca2c..f2d5cad 100644 --- a/src/squarecolor.rs +++ b/src/squarecolor.rs @@ -142,7 +142,7 @@ impl Display for SquareColor { SquareColor::BrightCyan => 'C', SquareColor::BrightWhite => 'W', }; - write!(f, "{}", c) + write!(f, "{c}") } } @@ -188,7 +188,7 @@ mod tests { #[test] fn squarecolor_char_roundtrip() { for sc in ALL_SQUARE_COLORS { - let c = format!("{}", sc).chars().next().unwrap(); + let c = format!("{sc}").chars().next().unwrap(); assert_eq!(SquareColor::try_from(c).unwrap(), sc) } }