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) } }