[board] Remove an unintentional recursion in fmt::Display for piece::Shape
This commit is contained in:
		
							parent
							
								
									8e9da6aeff
								
							
						
					
					
						commit
						ecc1ee85d4
					
				
					 1 changed files with 15 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -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<char> for Shape {
 | 
			
		|||
 | 
			
		||||
impl Into<char> for &Shape {
 | 
			
		||||
    fn into(self) -> char {
 | 
			
		||||
        self.clone().into()
 | 
			
		||||
        self._ascii_representation()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Into<char> 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)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue