pub struct SquareCoordinates(/* private fields */);Expand description
SquareCoordinates is a struct that represents the coordinates of a square on a chess board.
The coordinates are represented internally as a single usize value.
§Examples
use chessly::SquareCoordinates;
let square = SquareCoordinates::new(0, 0);
assert_eq!(square.file(), 0);
assert_eq!(square.rank(), 0);
assert_eq!(square.to_string(), "a1");
let square = SquareCoordinates::try_from("h8").unwrap();
assert_eq!(square.file(), 7);
assert_eq!(square.rank(), 7);Implementations§
Source§impl SquareCoordinates
impl SquareCoordinates
Sourcepub fn new(file: u8, rank: u8) -> Self
pub fn new(file: u8, rank: u8) -> Self
Creates a new SquareCoordinates from a file and a rank.
File and rank are zero-indexed.
§Panics
Panics if file or rank is out of range.
§Examples
use chessly::SquareCoordinates;
let square = SquareCoordinates::new(3, 5);
assert_eq!(square.file(), 3);
assert_eq!(square.rank(), 5);
assert_eq!(square.to_string(), "d6");Source§impl SquareCoordinates
impl SquareCoordinates
Sourcepub const fn file(&self) -> u8
pub const fn file(&self) -> u8
Returns the file (zero-indexed) of the square.
§Examples
use chessly::SquareCoordinates;
let square = SquareCoordinates::new(3, 5);
assert_eq!(square.file(), 3);Sourcepub const fn rank(&self) -> u8
pub const fn rank(&self) -> u8
Returns the rank (zero-indexed) of the square.
§Examples
use chessly::SquareCoordinates;
let square = SquareCoordinates::new(3, 5);
assert_eq!(square.rank(), 5);Sourcepub const fn board_index(&self) -> usize
pub const fn board_index(&self) -> usize
Returns the index of the square on the board (zero-indexed).
§Examples
use chessly::SquareCoordinates;
let square = SquareCoordinates::new(3, 5);
assert_eq!(square.board_index(), 43);Trait Implementations§
Source§impl Clone for SquareCoordinates
impl Clone for SquareCoordinates
Source§fn clone(&self) -> SquareCoordinates
fn clone(&self) -> SquareCoordinates
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SquareCoordinates
impl Debug for SquareCoordinates
Source§impl Display for SquareCoordinates
impl Display for SquareCoordinates
Source§impl PartialEq for SquareCoordinates
impl PartialEq for SquareCoordinates
Source§impl TryFrom<&str> for SquareCoordinates
impl TryFrom<&str> for SquareCoordinates
impl Copy for SquareCoordinates
impl Eq for SquareCoordinates
impl StructuralPartialEq for SquareCoordinates
Auto Trait Implementations§
impl Freeze for SquareCoordinates
impl RefUnwindSafe for SquareCoordinates
impl Send for SquareCoordinates
impl Sync for SquareCoordinates
impl Unpin for SquareCoordinates
impl UnwindSafe for SquareCoordinates
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more