Enum Square

Source
pub enum Square {
Show 64 variants A8, B8, C8, D8, E8, F8, G8, H8, A7, B7, C7, D7, E7, F7, G7, H7, A6, B6, C6, D6, E6, F6, G6, H6, A5, B5, C5, D5, E5, F5, G5, H5, A4, B4, C4, D4, E4, F4, G4, H4, A3, B3, C3, D3, E3, F3, G3, H3, A2, B2, C2, D2, E2, F2, G2, H2, A1, B1, C1, D1, E1, F1, G1, H1,
}
Expand description

§Chess board square

Square are identified with <file><rank> format:

  • file - Lowercase alphabet character from range [A-H]. Sometimes referred to as columns.
  • rank - Numeric character from range [1-8]. Sometimes referred to as rows.

Setup of white pieces is done on ranks 1 and 2, whilist setup of black pieces is done on ranks 7 and 8.

§Example

use chess_notation_parser::Square;

// Creation of squares is done with <&str>try_from() function
assert_eq!(Ok(Square::A1), Square::try_from("a1"));

// Only lowercase letters should be used
assert_eq!(Err("Invalid square input"), Square::try_from("A1"));

// Invalid input is rejected
assert_eq!(Err("Invalid square input"), Square::try_from("A9"));
assert_eq!(Err("Invalid square input"), Square::try_from("K1"));

Variants§

§

A8

§

B8

§

C8

§

D8

§

E8

§

F8

§

G8

§

H8

§

A7

§

B7

§

C7

§

D7

§

E7

§

F7

§

G7

§

H7

§

A6

§

B6

§

C6

§

D6

§

E6

§

F6

§

G6

§

H6

§

A5

§

B5

§

C5

§

D5

§

E5

§

F5

§

G5

§

H5

§

A4

§

B4

§

C4

§

D4

§

E4

§

F4

§

G4

§

H4

§

A3

§

B3

§

C3

§

D3

§

E3

§

F3

§

G3

§

H3

§

A2

§

B2

§

C2

§

D2

§

E2

§

F2

§

G2

§

H2

§

A1

§

B1

§

C1

§

D1

§

E1

§

F1

§

G1

§

H1

Implementations§

Source§

impl Square

Source

pub fn get_file(file: char) -> Result<Vec<Square>, &'static str>

Get a set of squares representing certain file

§Example
use chess_notation_parser::Square;

let file_a = Square::get_file('a').unwrap();
let mut iter = file_a.into_iter();

assert_eq!(Some(Square::A1), iter.next());
assert_eq!(Some(Square::A2), iter.next());
assert_eq!(Some(Square::A3), iter.next());
assert_eq!(Some(Square::A4), iter.next());
assert_eq!(Some(Square::A5), iter.next());
assert_eq!(Some(Square::A6), iter.next());
assert_eq!(Some(Square::A7), iter.next());
assert_eq!(Some(Square::A8), iter.next());
assert_eq!(None, iter.next());
Source

pub fn get_rank(rank: char) -> Result<Vec<Square>, &'static str>

Get a set of squares representing certain rank

§Example
use chess_notation_parser::Square;

let rank_a = Square::get_rank('2').unwrap();
let mut iter = rank_a.into_iter();

assert_eq!(Some(Square::A2), iter.next());
assert_eq!(Some(Square::B2), iter.next());
assert_eq!(Some(Square::C2), iter.next());
assert_eq!(Some(Square::D2), iter.next());
assert_eq!(Some(Square::E2), iter.next());
assert_eq!(Some(Square::F2), iter.next());
assert_eq!(Some(Square::G2), iter.next());
assert_eq!(Some(Square::H2), iter.next());
assert_eq!(None, iter.next());
Source

pub fn get_relative_neighbor( &self, x: i8, y: i8, ) -> Result<Square, &'static str>

Get relative neighbor using relative (x,y) coordinates

§Example
use chess_notation_parser::Square;

let d4 = Square::D4;

let d2 = d4.get_relative_neighbor(0, -2).unwrap();
assert_eq!(d2, Square::D2);

let e5 = d4.get_relative_neighbor(1, 1).unwrap();
assert_eq!(e5, Square::E5);
Source

pub fn get_file_char(&self) -> char

Get file char

Source

pub fn get_rank_char(&self) -> char

Get rank char

Trait Implementations§

Source§

impl Clone for Square

Source§

fn clone(&self) -> Square

Returns a duplicate 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

Formats the value using the given formatter. Read more
Source§

impl Display for Square

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<u8> for Square

Source§

fn from(square: u8) -> Self

Converts to this type from the input type.
Source§

impl Hash for Square

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

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,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Square

Source§

fn eq(&self, other: &Square) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<&str> for Square

Source§

type Error = &'static str

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

fn try_from(square: &str) -> Result<Self, Self::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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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

Source§

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

Source§

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.