[−][src]Enum pleco::core::Piece
All possible Types of Pieces on a chessboard, for both colors.
For a representation of Only Pieces (with no color attached), see PieceType
Variants
None
WhitePawn
WhiteKnight
WhiteBishop
WhiteRook
WhiteQueen
WhiteKing
BlackPawn
BlackKnight
BlackBishop
BlackRook
BlackQueen
BlackKing
Methods
impl Piece
[src]
pub fn player(self) -> Option<Player>
[src]
Returns the Player
of a piece, if any.
For an unsafe, "lossy" determination of a Player
, see Piece::player_lossy
.
Examples
use pleco::{Piece,Player}; let black_knight = Piece::BlackKnight; let player: Player = black_knight.player().unwrap(); assert_eq!(player, Player::Black);
The only discriminant that will return None
:
use pleco::{Piece,Player}; let piece = Piece::None; assert!(piece.player().is_none());
pub fn player_lossy(self) -> Player
[src]
Returns the Player
of a Piece
.
Undefined Behavior
If the discriminant is Piece::None
, the returned Player
will be undefined. This method
must be used only when a returned Piece
is guaranteed to exist.
For a safer version of this method that accounts for an undetermined player,
see Piece::player
.
Examples
use pleco::{Piece,Player}; let white_pawn = Piece::WhitePawn; let player: Player = white_pawn.player_lossy(); assert_eq!(player, Player::White);
The following will invoke undefined behavior, so do not use it.
use pleco::{Piece,Player}; let piece = Piece::None; let fake_player: Player = piece.player_lossy();
pub fn type_of(self) -> PieceType
[src]
Returns the PieceType
.
Examples
use pleco::{Piece,PieceType}; let white_queen = Piece::WhiteQueen; let no_piece = Piece::None; assert_eq!(white_queen.type_of(), PieceType::Q); assert_eq!(no_piece.type_of(), PieceType::None); let black_queen = Piece::BlackQueen; assert_eq!(white_queen.type_of(), black_queen.type_of());
pub fn player_piece(self) -> Option<(Player, PieceType)>
[src]
Returns the Player
and PieceType
of this piece, if any. If the discriminant is
Piece::None
, None
will be returned.
For an unsafe, "lossy" determination of a Player
and Piece
,
see Piece::player_piece_lossy
.
Examples
use pleco::{Piece,PieceType,Player}; let white_queen = Piece::WhiteQueen; let (player, piece) = white_queen.player_piece().unwrap(); assert_eq!(piece, PieceType::Q); assert_eq!(player, Player::White);
pub fn player_piece_lossy(self) -> (Player, PieceType)
[src]
Returns the Player
and PieceType
of a Piece
.
Undefined Behavior
If the discriminant is Piece::None
, the returned PieceType
will be correct, but
the Player
will be undefined.
For a safer version of this method that accounts for an undetermined player,
see Piece::player_piece
.
Examples
use pleco::{Piece,PieceType,Player}; let white_queen = Piece::WhiteQueen; let (player, piece) = white_queen.player_piece_lossy(); assert_eq!(piece, PieceType::Q); assert_eq!(player, Player::White);
Undefined behavior can be encountered by doing something akin to:
use pleco::{Piece,PieceType,Player}; let not_a_piece = Piece::None; let (wrong_player, piece) = not_a_piece.player_piece_lossy();
pub fn make(player: Player, piece_type: PieceType) -> Option<Piece>
[src]
Creates a Piece
from a Player
and PieceType
. If the PieceType
is either
PieceType::All
or PieceType::None
, the returned value will be None
.
For an unsafe, lossy version of this method, see Piece::make_lossy
.
Examples
use pleco::{Piece,PieceType,Player}; let black_knight = Piece::make(Player::Black, PieceType::N).unwrap(); assert_eq!(black_knight.type_of(), PieceType::N); assert_eq!(black_knight.player().unwrap(), Player::Black); let illegal_piece = Piece::make(Player::White, PieceType::All); assert!(illegal_piece.is_none());
pub fn make_lossy(player: Player, piece_type: PieceType) -> Piece
[src]
Creates a Piece
from a Player
and PieceType
.
Undefined Behavior
If the PieceType
is either PieceType::All
or PieceType::None
, undefined behavior will
follow. See Piece::make
for a safer version of this method.
Examples
use pleco::{Piece,PieceType,Player}; let black_knight = Piece::make_lossy(Player::Black, PieceType::N); assert_eq!(black_knight.type_of(), PieceType::N); assert_eq!(black_knight.player().unwrap(), Player::Black);
The following code snippet will give undefined behavior:
use pleco::{Piece,PieceType,Player}; let illegal_piece = Piece::make_lossy(Player::Black, PieceType::All);
pub fn character(self) -> Option<char>
[src]
Returns the character of a Piece
. If the Piece is Piece::None
, None
will be returned.
pub fn character_lossy(self) -> char
[src]
Trait Implementations
impl Clone for Piece
[src]
fn clone(&self) -> Piece
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Piece
[src]
impl PartialEq<Piece> for Piece
[src]
fn eq(&self, other: &Piece) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Display for Piece
[src]
impl Debug for Piece
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,