From ecc1ee85d408c0c48c80c1a1b4a484f161d32c23 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 26 Dec 2023 21:31:44 -0700 Subject: [PATCH] [board] Remove an unintentional recursion in fmt::Display for piece::Shape --- board/src/piece.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/board/src/piece.rs b/board/src/piece.rs index 359234d..a96b1b5 100644 --- a/board/src/piece.rs +++ b/board/src/piece.rs @@ -45,6 +45,17 @@ impl Shape { ] .into_iter() } + + fn _ascii_representation(&self) -> char { + match self { + Shape::Pawn => 'p', + Shape::Knight => 'N', + Shape::Bishop => 'B', + Shape::Rook => 'R', + Shape::Queen => 'Q', + Shape::King => 'K', + } + } } pub struct TryFromCharError; @@ -67,26 +78,20 @@ impl TryFrom for Shape { impl Into for &Shape { fn into(self) -> char { - self.clone().into() + self._ascii_representation() } } impl Into for Shape { fn into(self) -> char { - match self { - Shape::Pawn => 'p', - Shape::Knight => 'N', - Shape::Bishop => 'B', - Shape::Rook => 'R', - Shape::Queen => 'Q', - Shape::King => 'K', - } + self._ascii_representation() } } impl fmt::Display for Shape { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self) + let self_char: char = self.into(); + write!(f, "{}", self_char) } }