pub struct Square(/* private fields */);Expand description
A chessboard square stored in canonical A1-to-H8 order.
Implementations§
Source§impl Square
impl Square
Sourcepub const fn new(file: File, rank: Rank) -> Self
pub const fn new(file: File, rank: Rank) -> Self
Creates a square from its file and rank.
§Examples
use chessnut_move::protocol::{File, Rank, Square};
let square = Square::new(File::E, Rank::Four);
assert_eq!(square.to_string(), "e4");Sourcepub const fn from_index(index: usize) -> Option<Self>
pub const fn from_index(index: usize) -> Option<Self>
Creates a square from a canonical zero-based index.
Returns None when index is not less than SQUARE_COUNT.
§Examples
use chessnut_move::protocol::{File, Rank, Square};
assert_eq!(Square::from_index(0), Some(Square::new(File::A, Rank::One)));
assert_eq!(Square::from_index(64), None);Sourcepub const fn index(self) -> usize
pub const fn index(self) -> usize
Returns the canonical zero-based A1-to-H8 index.
§Examples
use chessnut_move::protocol::{File, Rank, Square};
assert_eq!(Square::new(File::A, Rank::One).index(), 0);
assert_eq!(Square::new(File::H, Rank::Eight).index(), 63);Trait Implementations§
impl Copy for Square
impl Eq for Square
Source§impl Ord for Square
impl Ord for Square
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Square
impl PartialOrd for Square
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 UnsafeUnpin for Square
impl UnwindSafe for Square
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