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

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

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

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

Get file char

Get rank char

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

Converts to this type from the input type.

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

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

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.