pub enum PieceType {
Pawn,
Knight,
Bishop,
Rook,
Queen,
King,
}Expand description
Represents the type of a chess piece
§Variants
Pawn: A pawnKnight: A knightBishop: A bishopRook: A rookQueen: A queenKing: A king
Variants§
Implementations§
Source§impl PieceType
impl PieceType
Sourcepub fn from_char(c: char) -> Option<PieceType>
pub fn from_char(c: char) -> Option<PieceType>
Gets the piece type from a character
§Arguments
c: The character to convert (only valid uppercase characters)
§Returns
The piece type if the character is valid, otherwise None
§Example
use chess_lab::constants::PieceType;
assert_eq!(PieceType::from_char('P'), Some(PieceType::Pawn));
assert_eq!(PieceType::from_char('N'), Some(PieceType::Knight));
assert_eq!(PieceType::from_char('B'), Some(PieceType::Bishop));
assert_eq!(PieceType::from_char('R'), Some(PieceType::Rook));
assert_eq!(PieceType::from_char('Q'), Some(PieceType::Queen));
assert_eq!(PieceType::from_char('K'), Some(PieceType::King));
assert_eq!(PieceType::from_char('x'), None);
assert_eq!(PieceType::from_char('y'), None);
assert_eq!(PieceType::from_char('p'), None);Sourcepub fn to_char(&self) -> char
pub fn to_char(&self) -> char
Gets the character representation of the piece type
§Returns
The character representation of the piece type
§Example
use chess_lab::constants::PieceType;
assert_eq!(PieceType::Pawn.to_char(), 'P');
assert_eq!(PieceType::Knight.to_char(), 'N');
assert_eq!(PieceType::Bishop.to_char(), 'B');
assert_eq!(PieceType::Rook.to_char(), 'R');
assert_eq!(PieceType::Queen.to_char(), 'Q');
assert_eq!(PieceType::King.to_char(), 'K');Trait Implementations§
impl Copy for PieceType
impl Eq for PieceType
impl StructuralPartialEq for PieceType
Auto Trait Implementations§
impl Freeze for PieceType
impl RefUnwindSafe for PieceType
impl Send for PieceType
impl Sync for PieceType
impl Unpin for PieceType
impl UnwindSafe for PieceType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more