#[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
sourceimpl Square
impl Square
sourcepub const unsafe fn new_unchecked(index: u32) -> Square
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
.
sourcepub fn from_coords(file: File, rank: Rank) -> Square
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);
sourcepub fn from_ascii(s: &[u8]) -> Result<Square, ParseSquareError>
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);
sourcepub fn file(self) -> File
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);
sourcepub fn rank(self) -> Rank
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);
sourcepub fn coords(self) -> (File, Rank)
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));
sourcepub fn offset(self, delta: i32) -> Option<Square>
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);
sourcepub unsafe fn offset_unchecked(self, delta: i32) -> Square
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
.
sourcepub fn xor(self, other: Square) -> Square
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.
sourcepub fn flip_horizontal(self) -> Square
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);
sourcepub fn flip_vertical(self) -> Square
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);
sourcepub fn flip_diagonal(self) -> Square
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);
sourcepub fn flip_anti_diagonal(self) -> Square
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);
sourcepub fn rotate_90(self) -> Square
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);
sourcepub fn rotate_180(self) -> Square
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);
sourcepub fn rotate_270(self) -> Square
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);
sourcepub fn is_light(self) -> bool
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());
Trait Implementations
sourceimpl Extend<Square> for Bitboard
impl Extend<Square> for Bitboard
sourcefn extend<T: IntoIterator<Item = Square>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Square>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl FromIterator<Square> for Bitboard
impl FromIterator<Square> for Bitboard
sourcefn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Square>,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Square>,
Creates a value from an iterator. Read more
sourceimpl FromStr for Square
impl FromStr for Square
type Err = ParseSquareError
type Err = ParseSquareError
The associated error which can be returned from parsing.
sourceimpl Ord for Square
impl Ord for Square
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<Square> for Square
impl PartialEq<Square> for Square
sourceimpl PartialOrd<Square> for Square
impl PartialOrd<Square> for Square
sourcefn partial_cmp(&self, other: &Square) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl Step for Square
Available on crate feature step
only.
impl Step for Square
step
only.sourcefn steps_between(start: &Self, end: &Self) -> Option<usize>
fn steps_between(start: &Self, end: &Self) -> Option<usize>
step_trait
)Returns the number of successor steps required to get from start
to end
. Read more
sourcefn forward_checked(start: Self, count: usize) -> Option<Self>
fn forward_checked(start: Self, count: usize) -> Option<Self>
step_trait
)Returns the value that would be obtained by taking the successor
of self
count
times. Read more
sourcefn backward_checked(start: Self, count: usize) -> Option<Self>
fn backward_checked(start: Self, count: usize) -> Option<Self>
step_trait
)Returns the value that would be obtained by taking the predecessor
of self
count
times. Read more
sourceunsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
step_trait
)Returns the value that would be obtained by taking the successor
of self
count
times. Read more
sourceunsafe fn backward_unchecked(start: Self, count: usize) -> Self
unsafe fn backward_unchecked(start: Self, count: usize) -> Self
step_trait
)Returns the value that would be obtained by taking the predecessor
of self
count
times. Read more
impl Copy for Square
impl Eq for Square
impl StructuralEq for Square
impl StructuralPartialEq for Square
Auto Trait Implementations
impl RefUnwindSafe for Square
impl Send for Square
impl Sync for Square
impl Unpin for Square
impl UnwindSafe for Square
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more