diff --git a/Cargo.lock b/Cargo.lock index 0010c38..847a157 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,6 +145,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "const-str" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e991226a70654b49d34de5ed064885f0bef0348a8e70018b8ff1ac80aa984a2" + [[package]] name = "const_for" version = "0.1.5" @@ -449,6 +455,7 @@ dependencies = [ "allocative", "arrayvec", "console", + "const-str", "const_for", "criterion", "crossbeam-channel", diff --git a/Cargo.toml b/Cargo.toml index 6e2f99a..f8a16e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ debug = true allocative = "0.3" arrayvec = "0.7" console = "0.15" +const-str = "0.6" const_for = "0.1" crossbeam-channel = "0.5" either = "1.13" diff --git a/src/repr/board.rs b/src/repr/board.rs index e3065db..616340f 100644 --- a/src/repr/board.rs +++ b/src/repr/board.rs @@ -88,22 +88,22 @@ pub struct Board { impl fmt::Display for Board { #[allow(clippy::repeat_once)] // clippy gets mad about when PADDING == 1 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let horiz_sep_line = "-".repeat((Self::SIZE * 2 + 1) as usize); + const HORIZ_SEP_LINE: &str = const_str::repeat!("-", (Board::SIZE * 2 + 1) as usize); // basically calculates the # of digits BOARD_SIZE needs const PADDING: usize = (Board::SIZE - 1).ilog10() as usize + 1; - let space_padding = " ".repeat(PADDING); + const SPACE_PADDING: &str = const_str::repeat!(" ", PADDING); // Print numbers at top so the board can be read more easier - write!(f, "{} ", space_padding)?; + write!(f, "{} ", SPACE_PADDING)?; for j in (0..Self::SIZE).rev() { write!(f, "{:0PADDING$} ", j)?; } writeln!(f)?; for i in (0..Self::SIZE).rev() { - writeln!(f, "{}{}", space_padding, horiz_sep_line)?; + writeln!(f, "{}{}", SPACE_PADDING, HORIZ_SEP_LINE)?; write!(f, "{:0PADDING$}|", i)?; for j in (0..Self::SIZE).rev() { @@ -120,7 +120,7 @@ impl fmt::Display for Board { } // put a line at the bottom of the board too - writeln!(f, " {}", horiz_sep_line)?; + writeln!(f, " {}", HORIZ_SEP_LINE)?; // Print the current score write!(