pub struct Piece {
pub color: Color,
pub piece_type: PieceType,
}Expand description
Represents a piece on the board with a color and a piece type
§Examples
use chess_lab::core::{Color, PieceType, Piece};
let piece = Piece::new(Color::White, PieceType::Pawn);
assert_eq!(piece.color, Color::White);
assert_eq!(piece.piece_type, PieceType::Pawn);
assert_eq!(piece.to_string(), "P");Fields§
§color: ColorThe color of the piece
piece_type: PieceTypeThe type of the piece
Implementations§
Source§impl Piece
impl Piece
Sourcepub fn new(color: Color, piece_type: PieceType) -> Piece
pub fn new(color: Color, piece_type: PieceType) -> Piece
Creates a new piece with a given color and piece type
§Arguments
color: The color of the piecepiece_type: The type of the piece
§Returns
A new piece with the given color and piece type
§Examples
use chess_lab::core::{Color, PieceType, Piece};
let piece = Piece::new(Color::White, PieceType::Pawn);
assert_eq!(piece.color, Color::White);
assert_eq!(piece.piece_type, PieceType::Pawn);Sourcepub fn from_fen(char: char) -> Result<Piece, PieceReprError>
pub fn from_fen(char: char) -> Result<Piece, PieceReprError>
Creates a new piece from a FEN character
§Arguments
char: The FEN character representing the piece
§Returns
A Result<Piece, PieceReprError> object
Ok(Piece): The new pieceErr(PieceReprError): If the FEN character is invalid
§Examples
use chess_lab::core::{Color, PieceType, Piece};
let piece = Piece::from_fen('P').unwrap();
assert_eq!(piece.color, Color::White);
assert_eq!(piece.piece_type, PieceType::Pawn);Trait Implementations§
impl Copy for Piece
impl StructuralPartialEq for Piece
Auto Trait Implementations§
impl Freeze for Piece
impl RefUnwindSafe for Piece
impl Send for Piece
impl Sync for Piece
impl Unpin for Piece
impl UnsafeUnpin for Piece
impl UnwindSafe for Piece
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