Enum pgn_reader::Square

source ·
#[repr(u8)]
pub enum Square {
Show 64 variants A1 = 0, B1 = 1, C1 = 2, D1 = 3, E1 = 4, F1 = 5, G1 = 6, H1 = 7, A2 = 8, B2 = 9, C2 = 10, D2 = 11, E2 = 12, F2 = 13, G2 = 14, H2 = 15, A3 = 16, B3 = 17, C3 = 18, D3 = 19, E3 = 20, F3 = 21, G3 = 22, H3 = 23, A4 = 24, B4 = 25, C4 = 26, D4 = 27, E4 = 28, F4 = 29, G4 = 30, H4 = 31, A5 = 32, B5 = 33, C5 = 34, D5 = 35, E5 = 36, F5 = 37, G5 = 38, H5 = 39, A6 = 40, B6 = 41, C6 = 42, D6 = 43, E6 = 44, F6 = 45, G6 = 46, H6 = 47, A7 = 48, B7 = 49, C7 = 50, D7 = 51, E7 = 52, F7 = 53, G7 = 54, H7 = 55, A8 = 56, B8 = 57, C8 = 58, D8 = 59, E8 = 60, F8 = 61, G8 = 62, H8 = 63,
}
Expand description

A square of the chessboard.

Variants§

§

A1 = 0

§

B1 = 1

§

C1 = 2

§

D1 = 3

§

E1 = 4

§

F1 = 5

§

G1 = 6

§

H1 = 7

§

A2 = 8

§

B2 = 9

§

C2 = 10

§

D2 = 11

§

E2 = 12

§

F2 = 13

§

G2 = 14

§

H2 = 15

§

A3 = 16

§

B3 = 17

§

C3 = 18

§

D3 = 19

§

E3 = 20

§

F3 = 21

§

G3 = 22

§

H3 = 23

§

A4 = 24

§

B4 = 25

§

C4 = 26

§

D4 = 27

§

E4 = 28

§

F4 = 29

§

G4 = 30

§

H4 = 31

§

A5 = 32

§

B5 = 33

§

C5 = 34

§

D5 = 35

§

E5 = 36

§

F5 = 37

§

G5 = 38

§

H5 = 39

§

A6 = 40

§

B6 = 41

§

C6 = 42

§

D6 = 43

§

E6 = 44

§

F6 = 45

§

G6 = 46

§

H6 = 47

§

A7 = 48

§

B7 = 49

§

C7 = 50

§

D7 = 51

§

E7 = 52

§

F7 = 53

§

G7 = 54

§

H7 = 55

§

A8 = 56

§

B8 = 57

§

C8 = 58

§

D8 = 59

§

E8 = 60

§

F8 = 61

§

G8 = 62

§

H8 = 63

Implementations§

source§

impl Square

source

pub const fn new(index: u32) -> Square

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);
source

pub const unsafe fn new_unchecked(index: u32) -> Square

Gets a Square from an integer index.

§Safety

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

source

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

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);
source

pub fn from_ascii(s: &[u8]) -> Result<Square, ParseSquareError>

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);
source

pub fn file(self) -> File

Gets the file.

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

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

pub fn rank(self) -> Rank

Gets the rank.

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

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

pub fn coords(self) -> (File, Rank)

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));
source

pub fn offset(self, delta: i32) -> Option<Square>

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);
source

pub unsafe fn offset_unchecked(self, delta: i32) -> Square

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.

source

pub fn xor(self, other: Square) -> Square

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

source

pub fn flip_horizontal(self) -> Square

Flip the square horizontally.

use shakmaty::Square;

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

pub fn flip_vertical(self) -> Square

Flip the square vertically.

use shakmaty::Square;

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

pub fn flip_diagonal(self) -> Square

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);
source

pub fn flip_anti_diagonal(self) -> Square

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);
source

pub fn rotate_90(self) -> Square

Rotate 90 degrees clockwise.

use shakmaty::Square;

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

pub fn rotate_180(self) -> Square

Rotate 180 degrees.

use shakmaty::Square;

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

pub fn rotate_270(self) -> Square

Rotate 270 degrees clockwise.

use shakmaty::Square;

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

pub fn is_light(self) -> bool

Tests is the square is a light square.

use shakmaty::Square;

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

pub fn is_dark(self) -> bool

Tests is the square is a dark square.

use shakmaty::Square;

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

pub fn distance(self, other: Square) -> u32

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);
source§

impl Square

source

pub const ALL: [Square; 64] = _

A1, B1, …, G8, H8.

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<(File, Rank)> for Square

source§

fn from(_: (File, Rank)) -> Square

Converts to this type from the input type.
source§

impl From<EnPassant> for Square

source§

fn from(ep: EnPassant) -> Square

Converts to this type from the input type.
source§

impl FromStr for Square

§

type Err = ParseSquareError

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

fn from_str(s: &str) -> Result<Square, ParseSquareError>

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 Sub for Square

§

type Output = i32

The resulting type after applying the - operator.
source§

fn sub(self, other: Square) -> i32

Performs the - operation. Read more
source§

impl TryFrom<i128> for Square

§

type Error = TryFromIntError

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

fn try_from(value: i128) -> Result<Square, <Square as TryFrom<i128>>::Error>

Performs the conversion.
source§

impl TryFrom<i16> for Square

§

type Error = TryFromIntError

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

fn try_from(value: i16) -> Result<Square, <Square as TryFrom<i16>>::Error>

Performs the conversion.
source§

impl TryFrom<i32> for Square

§

type Error = TryFromIntError

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

fn try_from(value: i32) -> Result<Square, <Square as TryFrom<i32>>::Error>

Performs the conversion.
source§

impl TryFrom<i64> for Square

§

type Error = TryFromIntError

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

fn try_from(value: i64) -> Result<Square, <Square as TryFrom<i64>>::Error>

Performs the conversion.
source§

impl TryFrom<i8> for Square

§

type Error = TryFromIntError

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

fn try_from(value: i8) -> Result<Square, <Square as TryFrom<i8>>::Error>

Performs the conversion.
source§

impl TryFrom<isize> for Square

§

type Error = TryFromIntError

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

fn try_from(value: isize) -> Result<Square, <Square as TryFrom<isize>>::Error>

Performs the conversion.
source§

impl TryFrom<u128> for Square

§

type Error = TryFromIntError

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

fn try_from(value: u128) -> Result<Square, <Square as TryFrom<u128>>::Error>

Performs the conversion.
source§

impl TryFrom<u16> for Square

§

type Error = TryFromIntError

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

fn try_from(value: u16) -> Result<Square, <Square as TryFrom<u16>>::Error>

Performs the conversion.
source§

impl TryFrom<u32> for Square

§

type Error = TryFromIntError

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

fn try_from(value: u32) -> Result<Square, <Square as TryFrom<u32>>::Error>

Performs the conversion.
source§

impl TryFrom<u64> for Square

§

type Error = TryFromIntError

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

fn try_from(value: u64) -> Result<Square, <Square as TryFrom<u64>>::Error>

Performs the conversion.
source§

impl TryFrom<u8> for Square

§

type Error = TryFromIntError

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

fn try_from(value: u8) -> Result<Square, <Square as TryFrom<u8>>::Error>

Performs the conversion.
source§

impl TryFrom<usize> for Square

§

type Error = TryFromIntError

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

fn try_from(value: usize) -> Result<Square, <Square as TryFrom<usize>>::Error>

Performs the conversion.
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
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.