Enum shakmaty::Square

source ·
#[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 of the chessboard.

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§

A1, B1, …, G8, H8.

Gets a Square from an integer index.

Panics

Panics if the index is not in the range 0..=63.

Examples
use shakmaty::Square;

assert_eq!(Square::new(0), Square::A1);
assert_eq!(Square::new(63), Square::H8);

Gets a Square from an integer index.

Safety

It is the callers responsibility to ensure it is in the range 0..=63.

Tries to get a square from file and rank.

Examples
use shakmaty::{Square, File, Rank};

assert_eq!(Square::from_coords(File::A, Rank::First), Square::A1);

Parses a square name.

Errors

Returns ParseSquareError if the input is not a valid square name in lowercase ASCII characters.

Example
use shakmaty::Square;
let sq = Square::from_ascii(b"a5")?;
assert_eq!(sq, Square::A5);

Gets the file.

Examples
use shakmaty::{Square, File};

assert_eq!(Square::A1.file(), File::A);
assert_eq!(Square::B2.file(), File::B);

Gets the rank.

Examples
use shakmaty::{Square, Rank};

assert_eq!(Square::A1.rank(), Rank::First);
assert_eq!(Square::B2.rank(), Rank::Second);

Gets file and rank.

Examples
use shakmaty::{Square, File, Rank};

assert_eq!(Square::A1.coords(), (File::A, Rank::First));
assert_eq!(Square::H8.coords(), (File::H, Rank::Eighth));

Calculates the offset from a square index.

Examples
use shakmaty::Square;

assert_eq!(Square::F3.offset(8), Some(Square::F4));
assert_eq!(Square::F3.offset(-1), Some(Square::E3));

assert_eq!(Square::F3.offset(48), None);

Calculates the offset from a square index without checking for overflow.

Safety

It is the callers responsibility to ensure that delta is a valid offset for self.

Return the bitwise XOR of the numeric square representations. For some operands this is a useful geometric transformation.

Flip the square horizontally.

use shakmaty::Square;

assert_eq!(Square::H1.flip_horizontal(), Square::A1);
assert_eq!(Square::D3.flip_horizontal(), Square::E3);

Flip the square vertically.

use shakmaty::Square;

assert_eq!(Square::A8.flip_vertical(), Square::A1);
assert_eq!(Square::D3.flip_vertical(), Square::D6);

Flip at the a1-h8 diagonal by swapping file and rank.

use shakmaty::Square;

assert_eq!(Square::A1.flip_diagonal(), Square::A1);
assert_eq!(Square::A3.flip_diagonal(), Square::C1);

Flip at the h1-a8 diagonal.

use shakmaty::Square;

assert_eq!(Square::A1.flip_anti_diagonal(), Square::H8);
assert_eq!(Square::A3.flip_anti_diagonal(), Square::F8);

Rotate 90 degrees clockwise.

use shakmaty::Square;

assert_eq!(Square::A1.rotate_90(), Square::A8);
assert_eq!(Square::A3.rotate_90(), Square::C8);

Rotate 180 degrees.

use shakmaty::Square;

assert_eq!(Square::A1.rotate_180(), Square::H8);
assert_eq!(Square::A3.rotate_180(), Square::H6);

Rotate 270 degrees clockwise.

use shakmaty::Square;

assert_eq!(Square::A1.rotate_270(), Square::H1);
assert_eq!(Square::A3.rotate_270(), Square::F1);

Tests is the square is a light square.

use shakmaty::Square;

assert!(Square::D1.is_light());
assert!(!Square::D8.is_light());

Tests is the square is a dark square.

use shakmaty::Square;

assert!(Square::E1.is_dark());
assert!(!Square::E8.is_dark());

The distance between the two squares, i.e. the number of king steps to get from one square to the other.

use shakmaty::Square;

assert_eq!(Square::A2.distance(Square::B5), 3);

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. 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.
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.
Converts to this type from the input type.
Converts to this type from the input type.
Creates a value from an iterator. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
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
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
🔬This is a nightly-only experimental API. (step_trait)
Returns the number of successor steps required to get from start to end. Read more
🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the successor of self count times. Read more
🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the predecessor of self count times. Read more
🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the successor of self count times. Read more
🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the predecessor of self count times. Read more
🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the successor of self count times. Read more
🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the predecessor of self count times. Read more
The resulting type after applying the - operator.
Performs the - operation. 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.
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.
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.
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.
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.

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
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.