Enum Color Copy item path Source #[repr(u8)]
pub enum Color {
White = 0,
Black = 1,
}Expand description Represents the color of a player, piece, square, etc. within a chess board.
In Western chess, White traditionally moves first, and therefore Color defaults to Color::White .
Number of color variants.
An array of both colors, starting with White.
An iterator over both colors, starting with White.
Creates a new Color from a set of bits.
bits must be [0,1].
§ Panics
If bits is greater than 1.
§ Example
let white = Color::from_bits(0 );
assert! (white.is_ok());
assert_eq! (white.unwrap(), Color::White);
let err = Color::from_bits(42 );
assert! (err.is_err());Creates a new Color from a set of bits, ignoring safety checks.
bits must be [0,1].
§ Panics
If bits is greater than 1 and debug assertions are enabled.
§ Example
let white = Color::from_bits(0 );
assert! (white.is_ok());
assert_eq! (white.unwrap(), Color::White);
let err = Color::from_bits(42 );
assert! (err.is_err());Creates a new Color from a bool, where false = White.
§ Example
let white = Color::from_bool(false );
assert_eq! (white, Color::White);
let black = Color::from_bool(true );
assert_eq! (black, Color::Black);Returns true if this Color is White.
Returns true if this Color is Black.
Returns a multiplier for negating numbers relative to this color.
§ Example
assert_eq! (Color::White.negation_multiplier(), 1 );
assert_eq! (Color::Black.negation_multiplier(), -1 );Returns this Color ’s opposite / inverse / enemy.
§ Example
assert_eq! (Color::White.opponent(), Color::Black);
assert_eq! (Color::Black.opponent(), Color::White);Returns this Color as a usize.
Will be 0 for White, 1 for Black.
Useful for indexing into lists.
§ Example
assert_eq! (Color::White.index(), 0 );
assert_eq! (Color::Black.index(), 1 );Returns this Color as a u8.
Will be 0 for White, 1 for Black.
Useful for bit twiddling.
§ Example
assert_eq! (Color::White.bits(), 0 );
assert_eq! (Color::Black.bits(), 1 );Creates a Color from a char, according to the Universal Chess Interface notation.
§ Example
let white = Color::from_uci('w' );
assert! (white.is_ok());
assert_eq! (white.unwrap(), Color::White);
let err = Color::from_uci('x' );
assert! (err.is_err());Creates a Color based on the ASCII case of the provided character, with uppercase being White and lowercase being Black.
Note this is intended to follow the Universal Chess Interface notation, but can be used in odd ways, such as trying to find the color of the char 'z' (Black).
§ Example
assert_eq! (Color::from_case('k' ), Color::Black);Fetches a human-readable name for this Color .
§ Example
let white = Color::White;
assert_eq! (white.name(), "white" );Performs copy-assignment from
source.
Read more Debug formatting displays a $type as its human-readable name and index value.
Returns the “default value” for a type.
Read more By default, a $type displays as a lowercase char.
Does the same as Self::from_uci , but only if s is one character in length.
The associated error which can be returned from parsing.
The returned type after indexing.
Performs the indexing (
container[index]) operation.
Read more Performs the mutable indexing (
container[index]) operation.
Read more The resulting type after applying the - operator.
Compares and returns the maximum of two values.
Read more Compares and returns the minimum of two values.
Read more Restrict a value to a certain interval.
Read more Tests for self and other values to be equal, and is used by ==.
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more Converts the given value to a
String.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.