Enum chess_notation_parser::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
sourceimpl Square
impl Square
sourcepub fn get_file(file: char) -> Result<Vec<Square>, &'static str>
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());sourcepub fn get_rank(rank: char) -> Result<Vec<Square>, &'static str>
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());sourcepub fn get_relative_neighbor(
&self,
x: i8,
y: i8
) -> Result<Square, &'static str>
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);sourcepub fn get_file_char(&self) -> char
pub fn get_file_char(&self) -> char
Get file char
sourcepub fn get_rank_char(&self) -> char
pub fn get_rank_char(&self) -> char
Get rank char
Trait Implementations
sourceimpl Ord for Square
impl Ord 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
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