[board] Remove an unintentional recursion in fmt::Display for piece::Shape

This commit is contained in:
Eryn Wells 2023-12-26 21:31:44 -07:00
parent 8e9da6aeff
commit ecc1ee85d4

View file

@ -45,6 +45,17 @@ impl Shape {
] ]
.into_iter() .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; pub struct TryFromCharError;
@ -67,26 +78,20 @@ impl TryFrom<char> for Shape {
impl Into<char> for &Shape { impl Into<char> for &Shape {
fn into(self) -> char { fn into(self) -> char {
self.clone().into() self._ascii_representation()
} }
} }
impl Into<char> for Shape { impl Into<char> for Shape {
fn into(self) -> char { fn into(self) -> char {
match self { self._ascii_representation()
Shape::Pawn => 'p',
Shape::Knight => 'N',
Shape::Bishop => 'B',
Shape::Rook => 'R',
Shape::Queen => 'Q',
Shape::King => 'K',
}
} }
} }
impl fmt::Display for Shape { impl fmt::Display for Shape {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self) let self_char: char = self.into();
write!(f, "{}", self_char)
} }
} }