[−][src]Enum pgn_reader::Square
A square index.
Variants
A1B1C1D1E1F1G1H1A2B2C2D2E2F2G2H2A3B3C3D3E3F3G3H3A4B4C4D4E4F4G4H4A5B5C5D5E5F5G5H5A6B6C6D6E6F6G6H6A7B7C7D7E7F7G7H7A8B8C8D8E8F8G8H8Methods
impl Square[src]
pub fn new(index: i8) -> Square[src]
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);
pub fn from_index(index: i8) -> Option<Square>[src]
Tries to get a Square from an integer index in the range 0..=63.
Examples
use shakmaty::Square; assert_eq!(Square::from_index(0), Some(Square::A1)); assert_eq!(Square::from_index(63), Some(Square::H8)); assert_eq!(Square::from_index(64), None);
pub unsafe fn from_index_unchecked(index: i8) -> Square[src]
Gets a Square from an integer index.
Unsafety
It is the callers responsibility to ensure it is in the range 0..=63.
pub fn from_coords(file: File, rank: Rank) -> Square[src]
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);
pub fn from_ascii(s: &[u8]) -> Result<Square, ParseSquareError>[src]
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);
pub fn file(self) -> File[src]
Gets the file.
Examples
use shakmaty::{Square, File}; assert_eq!(Square::A1.file(), File::A); assert_eq!(Square::B2.file(), File::B);
pub fn rank(self) -> Rank[src]
Gets the rank.
Examples
use shakmaty::{Square, Rank}; assert_eq!(Square::A1.rank(), Rank::First); assert_eq!(Square::B2.rank(), Rank::Second);
pub fn coords(self) -> (File, Rank)[src]
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));
pub fn offset(self, delta: i8) -> Option<Square>[src]
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);
pub fn flip_horizontal(self) -> Square[src]
Flip the square horizontally.
use shakmaty::Square; assert_eq!(Square::H1.flip_horizontal(), Square::A1); assert_eq!(Square::D3.flip_horizontal(), Square::E3);
pub fn flip_vertical(self) -> Square[src]
Flip the square vertically.
use shakmaty::Square; assert_eq!(Square::A8.flip_vertical(), Square::A1); assert_eq!(Square::D3.flip_vertical(), Square::D6);
pub fn flip_diagonal(self) -> Square[src]
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);
pub fn is_light(self) -> bool[src]
Tests is the square is a light square.
use shakmaty::Square; assert!(Square::D1.is_light()); assert!(!Square::D8.is_light());
pub fn is_dark(self) -> bool[src]
Tests is the square is a dark square.
use shakmaty::Square; assert!(Square::E1.is_dark()); assert!(!Square::E8.is_dark());
pub fn distance(self, other: Square) -> i8[src]
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);
pub fn combine(self, rank: Square) -> Square[src]
Combines two squares, taking the file from the first and the rank from the second.
use shakmaty::Square; assert_eq!(Square::D3.combine(Square::F5), Square::D5);
Trait Implementations
impl PartialEq<Square> for Square[src]
fn eq(&self, other: &Square) -> bool[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl Display for Square[src]
impl FromStr for Square[src]
type Err = ParseSquareError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Square, ParseSquareError>[src]
impl Clone for Square[src]
fn clone(&self) -> Square[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl PartialOrd<Square> for Square[src]
fn partial_cmp(&self, other: &Square) -> Option<Ordering>[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool1.0.0[src]
This method tests less than (for self and other) and is used by the < operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool1.0.0[src]
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool1.0.0[src]
This method tests greater than (for self and other) and is used by the > operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool1.0.0[src]
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl From<(File, Rank)> for Square[src]
impl Debug for Square[src]
impl Copy for Square[src]
impl Sub<Square> for Square[src]
type Output = i8
The resulting type after applying the - operator.
fn sub(self, other: Square) -> i8[src]
impl Eq for Square[src]
impl TryFrom<u8> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: u8) -> Result<Square, <Square as TryFrom<u8>>::Error>[src]
impl TryFrom<usize> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: usize) -> Result<Square, <Square as TryFrom<usize>>::Error>[src]
impl TryFrom<i128> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: i128) -> Result<Square, <Square as TryFrom<i128>>::Error>[src]
impl TryFrom<isize> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: isize) -> Result<Square, <Square as TryFrom<isize>>::Error>[src]
impl TryFrom<u32> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: u32) -> Result<Square, <Square as TryFrom<u32>>::Error>[src]
impl TryFrom<i32> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: i32) -> Result<Square, <Square as TryFrom<i32>>::Error>[src]
impl TryFrom<i64> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: i64) -> Result<Square, <Square as TryFrom<i64>>::Error>[src]
impl TryFrom<i16> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: i16) -> Result<Square, <Square as TryFrom<i16>>::Error>[src]
impl TryFrom<u64> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: u64) -> Result<Square, <Square as TryFrom<u64>>::Error>[src]
impl TryFrom<i8> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: i8) -> Result<Square, <Square as TryFrom<i8>>::Error>[src]
impl TryFrom<u128> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: u128) -> Result<Square, <Square as TryFrom<u128>>::Error>[src]
impl TryFrom<u16> for Square[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: u16) -> Result<Square, <Square as TryFrom<u16>>::Error>[src]
impl Hash for Square[src]
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher, [src]
__H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher]. Read more
impl Ord for Square[src]
fn cmp(&self, other: &Square) -> Ordering[src]
fn max(self, other: Self) -> Self1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self[src]
clamp)Returns max if self is greater than max, and min if self is less than min. Otherwise this will return self. Panics if min > max. Read more
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T> From for T[src]
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,