#[repr(u8)]
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 chess board.

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

Implementations§

The total number of [$name]s.

All of the variants of [$name]s, indexable by their discriminant.

All of the variant names of [$name], indexable by their discriminant.

Returns an iterator through all [$type] variants.

Returns the name of the variant as a string.

Creates a new square of the provided file and rank.

Returns the file the square is on.

Returns the rank the square is on.

Returns true if this is a dark-colored square.

Returns true if this is a light-colored square.

Returns this square from the perspective of flipping the board left-to-right.

Returns this square from the perspective of flipping the board top-to-bottom.

If color is Color::White, returns the original square. If color is Color::Black, returns the square on the same file but whose rank is from the black player’s perspective.

Examples

assert_eq!(Square::B3, Square::B3.from_perspective(Color::White));
assert_eq!(Square::B6, Square::B3.from_perspective(Color::Black));
assert_eq!(Square::C1, Square::C8.from_perspective(Color::Black));

The number of steps a king would have to move in order to be on the file of the other square.

The number of steps a king would have to move in order to be on the rank of the other square.

The number of steps a king would have to move in order to wind up on the other square.

Performs wrapping addition of a Direction to a Square. Note that this wraps around files and ranks.

Examples:

assert_eq!(Square::C4, Square::A3.wrapping_add(Direction::ENE));
assert_eq!(Square::A5, Square::H5.wrapping_add(Direction::E));
assert_eq!(Square::D2, Square::D8.wrapping_add(Direction::NN));
assert_eq!(Square::H8, Square::A2.wrapping_add(Direction::SSW));

Performs wrapping addition of a Direction from a Square. Note that this wraps around files and ranks.

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
Performs the &= operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
Performs the |= operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
Performs the ^= operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
The resulting type after applying the ! operator.
Performs the unary ! operation. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. 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
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.