Enum cozy_chess::Square

source ·
pub enum Square {
Show 64 variants A1, B1, C1, D1, E1, F1, G1, H1, A2, B2, C2, D2, E2, F2, G2, H2, A3, B3, C3, D3, E3, F3, G3, H3, A4, B4, C4, D4, E4, F4, G4, H4, A5, B5, C5, D5, E5, F5, G5, H5, A6, B6, C6, D6, E6, F6, G6, H6, A7, B7, C7, D7, E7, F7, G7, H7, A8, B8, C8, D8, E8, F8, G8, H8,
}
Expand description

A square on a chessboard. Squares are ordered in rank-major order (A1, B1, C1, … H8).

Variants§

§

A1

The A1 square.

§

B1

The B1 square.

§

C1

The C1 square.

§

D1

The D1 square.

§

E1

The E1 square.

§

F1

The F1 square.

§

G1

The G1 square.

§

H1

The H1 square.

§

A2

The A2 square.

§

B2

The B2 square.

§

C2

The C2 square.

§

D2

The D2 square.

§

E2

The E2 square.

§

F2

The F2 square.

§

G2

The G2 square.

§

H2

The H2 square.

§

A3

The A3 square.

§

B3

The B3 square.

§

C3

The C3 square.

§

D3

The D3 square.

§

E3

The E3 square.

§

F3

The F3 square.

§

G3

The G3 square.

§

H3

The H3 square.

§

A4

The A4 square.

§

B4

The B4 square.

§

C4

The C4 square.

§

D4

The D4 square.

§

E4

The E4 square.

§

F4

The F4 square.

§

G4

The G4 square.

§

H4

The H4 square.

§

A5

The A5 square.

§

B5

The B5 square.

§

C5

The C5 square.

§

D5

The D5 square.

§

E5

The E5 square.

§

F5

The F5 square.

§

G5

The G5 square.

§

H5

The H5 square.

§

A6

The A6 square.

§

B6

The B6 square.

§

C6

The C6 square.

§

D6

The D6 square.

§

E6

The E6 square.

§

F6

The F6 square.

§

G6

The G6 square.

§

H6

The H6 square.

§

A7

The A7 square.

§

B7

The B7 square.

§

C7

The C7 square.

§

D7

The D7 square.

§

E7

The E7 square.

§

F7

The F7 square.

§

G7

The G7 square.

§

H7

The H7 square.

§

A8

The A8 square.

§

B8

The B8 square.

§

C8

The C8 square.

§

D8

The D8 square.

§

E8

The E8 square.

§

F8

The F8 square.

§

G8

The G8 square.

§

H8

The H8 square.

Implementations§

source§

impl Square

source

pub const NUM: usize = 64usize

The number of Square variants.

source

pub const ALL: [Square; 64] = _

An array of all Square variants.

source

pub const fn try_index(index: usize) -> Option<Square>

Checked version of Square::index.

source

pub fn index(index: usize) -> Square

Convert an index to a Square.

§Panics

Panic if the index is out of bounds.

source

pub const fn index_const(index: usize) -> Square

const version of Square::index.

§Panics

Panic if the index is out of bounds.

source§

impl Square

source

pub const fn new(file: File, rank: Rank) -> Square

Make a square from a file and a rank.

§Examples
assert_eq!(Square::new(File::A, Rank::First), Square::A1);
source

pub const fn file(self) -> File

Get the file of this square.

§Examples
assert_eq!(Square::A1.file(), File::A);
source

pub const fn rank(self) -> Rank

Get the rank of this square.

§Examples
assert_eq!(Square::A1.rank(), Rank::First);
source

pub const fn bitboard(self) -> BitBoard

Get a bitboard with this square set.

assert_eq!(Square::B2.bitboard(), bitboard! {
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    . X . . . . . .
    . . . . . . . .
});
source

pub const fn offset(self, file_offset: i8, rank_offset: i8) -> Square

Offsets the square towards the top right.

§Panics

Panic if the offset would put the square out of bounds. See Square::try_offset for a non-panicking variant.

§Examples
assert_eq!(Square::A1.offset(1, 2), Square::B3);
source

pub const fn try_offset( self, file_offset: i8, rank_offset: i8 ) -> Option<Square>

Non-panicking version of Square::offset.

§Errors

See Square::offset’s panics.

source

pub const fn flip_file(self) -> Square

Flip the file of this square.

§Examples
assert_eq!(Square::A1.flip_file(), Square::H1);
source

pub const fn flip_rank(self) -> Square

Flip the rank of this square.

§Examples
assert_eq!(Square::A1.flip_rank(), Square::A8);
source

pub const fn relative_to(self, color: Color) -> Square

Get a square relative to some color. This flips the square if viewing from black’s perspective.

§Examples
assert_eq!(Square::A1.relative_to(Color::White), Square::A1);
assert_eq!(Square::A1.relative_to(Color::Black), Square::A8);

Trait Implementations§

source§

impl Clone for Square

source§

fn clone(&self) -> Square

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Square

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Display for Square

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<Square> for BitBoard

source§

fn from(value: Square) -> BitBoard

Converts to this type from the input type.
source§

impl FromIterator<Square> for BitBoard

source§

fn from_iter<T>(iter: T) -> BitBoard
where T: IntoIterator<Item = Square>,

Creates a value from an iterator. Read more
source§

impl FromStr for Square

§

type Err = SquareParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Square, <Square as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Square

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Square

source§

fn cmp(&self, other: &Square) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Square

source§

fn eq(&self, other: &Square) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Square

source§

fn partial_cmp(&self, other: &Square) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Square

source§

impl Eq for Square

source§

impl StructuralPartialEq for Square

Auto Trait Implementations§

§

impl Freeze for Square

§

impl RefUnwindSafe for Square

§

impl Send for Square

§

impl Sync for Square

§

impl Unpin for Square

§

impl UnwindSafe for Square

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.