1
0
Fork 0
This commit is contained in:
Paul-Nicolas Madelaine 2025-11-17 22:07:04 +01:00
parent c0e915f1b4
commit 00261d95c1
9 changed files with 102 additions and 96 deletions

View file

@ -1,6 +1,6 @@
use std::iter::ExactSizeIterator; use core::iter::ExactSizeIterator;
use std::iter::FusedIterator; use core::iter::FusedIterator;
use std::mem::MaybeUninit; use core::mem::MaybeUninit;
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct ArrayVec<T: Copy, const N: usize> { pub(crate) struct ArrayVec<T: Copy, const N: usize> {
@ -37,7 +37,7 @@ impl<T: Copy, const N: usize> ArrayVec<T, N> {
} }
#[inline] #[inline]
pub(crate) fn as_slice_mut(&mut self) -> &mut [T] { pub(crate) fn as_slice_mut(&mut self) -> &mut [T] {
unsafe { std::mem::transmute::<_, &mut [T]>(self.array.get_unchecked_mut(0..self.len)) } unsafe { core::mem::transmute::<_, &mut [T]>(self.array.get_unchecked_mut(0..self.len)) }
} }
} }
impl<'l, T: Copy, const N: usize> IntoIterator for &'l ArrayVec<T, N> { impl<'l, T: Copy, const N: usize> IntoIterator for &'l ArrayVec<T, N> {

View file

@ -2,8 +2,8 @@
use crate::board::*; use crate::board::*;
use std::iter::ExactSizeIterator; use core::iter::ExactSizeIterator;
use std::iter::FusedIterator; use core::iter::FusedIterator;
/// A set of squares. /// A set of squares.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -87,46 +87,46 @@ impl Bitboard {
} }
} }
impl std::ops::BitOr for Bitboard { impl core::ops::BitOr for Bitboard {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn bitor(self, rhs: Self) -> Self::Output { fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0) Self(self.0 | rhs.0)
} }
} }
impl std::ops::BitAnd for Bitboard { impl core::ops::BitAnd for Bitboard {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn bitand(self, rhs: Self) -> Self::Output { fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0) Self(self.0 & rhs.0)
} }
} }
impl std::ops::BitXor for Bitboard { impl core::ops::BitXor for Bitboard {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn bitxor(self, rhs: Self) -> Self::Output { fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0 ^ rhs.0) Self(self.0 ^ rhs.0)
} }
} }
impl std::ops::BitOrAssign for Bitboard { impl core::ops::BitOrAssign for Bitboard {
#[inline] #[inline]
fn bitor_assign(&mut self, rhs: Self) { fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0; self.0 |= rhs.0;
} }
} }
impl std::ops::BitAndAssign for Bitboard { impl core::ops::BitAndAssign for Bitboard {
#[inline] #[inline]
fn bitand_assign(&mut self, rhs: Self) { fn bitand_assign(&mut self, rhs: Self) {
self.0 &= rhs.0; self.0 &= rhs.0;
} }
} }
impl std::ops::BitXorAssign for Bitboard { impl core::ops::BitXorAssign for Bitboard {
#[inline] #[inline]
fn bitxor_assign(&mut self, rhs: Self) { fn bitxor_assign(&mut self, rhs: Self) {
self.0 ^= rhs.0; self.0 ^= rhs.0;
} }
} }
impl std::ops::Not for Bitboard { impl core::ops::Not for Bitboard {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn not(self) -> Self::Output { fn not(self) -> Self::Output {
@ -182,8 +182,8 @@ impl ExactSizeIterator for Bitboard {
} }
} }
impl std::fmt::Debug for Bitboard { impl core::fmt::Debug for Bitboard {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Bitboard(0x{:016X})", self.0) write!(f, "Bitboard(0x{:016X})", self.0)
} }
} }

View file

@ -72,7 +72,7 @@ impl Color {
} }
} }
impl std::ops::Not for Color { impl core::ops::Not for Color {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn not(self) -> Self::Output { fn not(self) -> Self::Output {
@ -126,7 +126,7 @@ impl File {
#[inline] #[inline]
pub const unsafe fn new_unchecked(index: u8) -> Self { pub const unsafe fn new_unchecked(index: u8) -> Self {
debug_assert!(index < 8); debug_assert!(index < 8);
unsafe { std::mem::transmute(index) } unsafe { core::mem::transmute(index) }
} }
#[inline] #[inline]
@ -166,9 +166,9 @@ impl File {
} }
} }
impl std::fmt::Display for File { impl core::fmt::Display for File {
#[inline] #[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.to_char()) write!(f, "{}", self.to_char())
} }
} }
@ -216,7 +216,7 @@ impl Rank {
#[inline] #[inline]
pub const unsafe fn new_unchecked(index: u8) -> Self { pub const unsafe fn new_unchecked(index: u8) -> Self {
debug_assert!(index < 8); debug_assert!(index < 8);
unsafe { std::mem::transmute(index) } unsafe { core::mem::transmute(index) }
} }
#[inline] #[inline]
@ -261,9 +261,9 @@ impl Rank {
} }
} }
impl std::fmt::Display for Rank { impl core::fmt::Display for Rank {
#[inline] #[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.to_char()) write!(f, "{}", self.to_char())
} }
} }
@ -315,7 +315,7 @@ impl Square {
#[inline] #[inline]
pub const unsafe fn new_unchecked(index: u8) -> Self { pub const unsafe fn new_unchecked(index: u8) -> Self {
debug_assert!(index < 64); debug_assert!(index < 64);
unsafe { std::mem::transmute(index) } unsafe { core::mem::transmute(index) }
} }
#[inline] #[inline]
@ -422,9 +422,9 @@ impl Square {
} }
} }
impl std::fmt::Display for Square { impl core::fmt::Display for Square {
#[inline] #[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.write_str(self.to_str()) f.write_str(self.to_str())
} }
} }
@ -432,14 +432,14 @@ impl std::fmt::Display for Square {
/// An error while parsing a [`Square`]. /// An error while parsing a [`Square`].
#[derive(Debug)] #[derive(Debug)]
pub struct ParseSquareError; pub struct ParseSquareError;
impl std::fmt::Display for ParseSquareError { impl core::fmt::Display for ParseSquareError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("invalid square syntax") f.write_str("invalid square syntax")
} }
} }
impl std::error::Error for ParseSquareError {} impl core::error::Error for ParseSquareError {}
impl std::str::FromStr for Square { impl core::str::FromStr for Square {
type Err = ParseSquareError; type Err = ParseSquareError;
#[inline] #[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -484,7 +484,7 @@ impl OptionSquare {
#[inline] #[inline]
pub(crate) fn from_square(square: Square) -> Self { pub(crate) fn from_square(square: Square) -> Self {
unsafe { std::mem::transmute(square) } unsafe { core::mem::transmute(square) }
} }
#[inline] #[inline]
@ -558,7 +558,7 @@ impl Role {
#[inline] #[inline]
pub(crate) unsafe fn transmute(i: u8) -> Self { pub(crate) unsafe fn transmute(i: u8) -> Self {
debug_assert!(i >= 1 && i < 7); debug_assert!(i >= 1 && i < 7);
unsafe { std::mem::transmute(i) } unsafe { core::mem::transmute(i) }
} }
} }
@ -574,14 +574,14 @@ impl<T> ByRole<T> {
#[inline] #[inline]
pub const fn get(&self, role: Role) -> &T { pub const fn get(&self, role: Role) -> &T {
let i = unsafe { (role as usize).unchecked_sub(1) }; let i = unsafe { (role as usize).unchecked_sub(1) };
unsafe { std::hint::assert_unchecked(i < 6) }; unsafe { core::hint::assert_unchecked(i < 6) };
&self.0[i] &self.0[i]
} }
#[inline] #[inline]
pub const fn get_mut(&mut self, role: Role) -> &mut T { pub const fn get_mut(&mut self, role: Role) -> &mut T {
let i = unsafe { (role as usize).unchecked_sub(1) }; let i = unsafe { (role as usize).unchecked_sub(1) };
unsafe { std::hint::assert_unchecked(i < 6) }; unsafe { core::hint::assert_unchecked(i < 6) };
&mut self.0[i] &mut self.0[i]
} }
@ -673,11 +673,11 @@ impl Direction {
#[inline] #[inline]
const unsafe fn transmute(value: u8) -> Self { const unsafe fn transmute(value: u8) -> Self {
debug_assert!(value < 8); debug_assert!(value < 8);
unsafe { std::mem::transmute(value) } unsafe { core::mem::transmute(value) }
} }
} }
impl std::ops::Not for Direction { impl core::ops::Not for Direction {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn not(self) -> Self::Output { fn not(self) -> Self::Output {

View file

@ -72,6 +72,10 @@
//! - chess960 and other variants //! - chess960 and other variants
//! - etc. //! - etc.
#![no_std]
extern crate alloc;
pub(crate) mod array_vec; pub(crate) mod array_vec;
pub(crate) mod lookup; pub(crate) mod lookup;
pub(crate) mod magics; pub(crate) mod magics;

View file

@ -7,9 +7,9 @@ use crate::position::*;
use crate::san::*; use crate::san::*;
use crate::uci::*; use crate::uci::*;
use std::convert::Infallible; use core::convert::Infallible;
use std::iter::{ExactSizeIterator, FusedIterator}; use core::iter::{ExactSizeIterator, FusedIterator};
use std::ops::ControlFlow; use core::ops::ControlFlow;
/// A legal move. /// A legal move.
#[must_use] #[must_use]
@ -299,7 +299,7 @@ impl<'l> Moves<'l> {
#[inline] #[inline]
pub fn sort_by<F>(&mut self, mut compare: F) pub fn sort_by<F>(&mut self, mut compare: F)
where where
F: FnMut(Move, Move) -> std::cmp::Ordering, F: FnMut(Move, Move) -> core::cmp::Ordering,
{ {
self.array.as_slice_mut().sort_unstable_by(|a, b| { self.array.as_slice_mut().sort_unstable_by(|a, b| {
compare( compare(

View file

@ -8,9 +8,9 @@ use crate::san::*;
use crate::setup::*; use crate::setup::*;
use crate::uci::*; use crate::uci::*;
use std::convert::Infallible; use core::convert::Infallible;
use std::iter::{ExactSizeIterator, FusedIterator}; use core::iter::{ExactSizeIterator, FusedIterator};
use std::ops::ControlFlow; use core::ops::ControlFlow;
/// **A chess position.** /// **A chess position.**
/// ///
@ -462,8 +462,8 @@ impl Position {
} }
} }
impl std::fmt::Debug for Position { impl core::fmt::Debug for Position {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
f.debug_tuple("Position") f.debug_tuple("Position")
.field(&TextRecord(self.as_setup())) .field(&TextRecord(self.as_setup()))
.finish() .finish()
@ -629,10 +629,10 @@ impl Position {
.chain(theirs.bishop().map(|sq| lookup::bishop(sq, blockers))) .chain(theirs.bishop().map(|sq| lookup::bishop(sq, blockers)))
.chain(theirs.rook().map(|sq| lookup::rook(sq, blockers))) .chain(theirs.rook().map(|sq| lookup::rook(sq, blockers)))
.chain(theirs.knight().map(|sq| lookup::knight(sq))) .chain(theirs.knight().map(|sq| lookup::knight(sq)))
.chain(std::iter::once( .chain(core::iter::once(
theirs.pawn().trans(!forward).trans(Direction::East), theirs.pawn().trans(!forward).trans(Direction::East),
)) ))
.chain(std::iter::once( .chain(core::iter::once(
theirs.pawn().trans(!forward).trans(Direction::West), theirs.pawn().trans(!forward).trans(Direction::West),
)) ))
.reduce_or() .reduce_or()
@ -659,7 +659,7 @@ impl Position {
.trans_unchecked(Direction::East) .trans_unchecked(Direction::East)
}; };
if global_mask_to.contains(to) { if global_mask_to.contains(to) {
moves.extend(std::iter::once(RawMove { moves.extend(core::iter::once(RawMove {
kind: MoveType::CastleShort, kind: MoveType::CastleShort,
from, from,
to, to,
@ -680,7 +680,7 @@ impl Position {
.trans_unchecked(Direction::West) .trans_unchecked(Direction::West)
}; };
if global_mask_to.contains(to) { if global_mask_to.contains(to) {
moves.extend(std::iter::once(RawMove { moves.extend(core::iter::once(RawMove {
kind: MoveType::CastleLong, kind: MoveType::CastleLong,
from, from,
to, to,
@ -823,7 +823,7 @@ impl Position {
& (!pinned | lookup::segment(king_square, to)) & (!pinned | lookup::segment(king_square, to))
{ {
moves.en_passant_is_legal()?; moves.en_passant_is_legal()?;
moves.extend(std::iter::once(RawMove { moves.extend(core::iter::once(RawMove {
kind: MoveType::EnPassant, kind: MoveType::EnPassant,
from, from,
to, to,
@ -1089,7 +1089,7 @@ impl MoveGen<Infallible> for MateMoveGenImpl {
struct MoveAndPromote<I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator> { struct MoveAndPromote<I: Iterator<Item = RawMove> + ExactSizeIterator + FusedIterator> {
role: u8, role: u8,
inner: I, inner: I,
cur: std::mem::MaybeUninit<RawMove>, cur: core::mem::MaybeUninit<RawMove>,
} }
impl<I> MoveAndPromote<I> impl<I> MoveAndPromote<I>
where where
@ -1100,7 +1100,7 @@ where
Self { Self {
role: 1, role: 1,
inner, inner,
cur: std::mem::MaybeUninit::uninit(), cur: core::mem::MaybeUninit::uninit(),
} }
} }
} }

View file

@ -48,8 +48,8 @@ pub(crate) enum SanSuffix {
Checkmate, Checkmate,
} }
impl std::fmt::Display for San { impl core::fmt::Display for San {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self.inner { match self.inner {
SanInner::Castle(CastlingSide::Short) => write!(f, "O-O")?, SanInner::Castle(CastlingSide::Short) => write!(f, "O-O")?,
SanInner::Castle(CastlingSide::Long) => write!(f, "O-O-O")?, SanInner::Castle(CastlingSide::Long) => write!(f, "O-O-O")?,
@ -88,13 +88,13 @@ impl std::fmt::Display for San {
} }
} }
impl std::fmt::Debug for San { impl core::fmt::Debug for San {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_tuple("San").field(&self.to_string()).finish() write!(f, "San(\"{self}\")")
} }
} }
impl std::str::FromStr for San { impl core::str::FromStr for San {
type Err = ParseSanError; type Err = ParseSanError;
#[inline] #[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -105,12 +105,12 @@ impl std::str::FromStr for San {
/// A syntax error when parsing [`San`] notation. /// A syntax error when parsing [`San`] notation.
#[derive(Debug)] #[derive(Debug)]
pub struct ParseSanError; pub struct ParseSanError;
impl std::fmt::Display for ParseSanError { impl core::fmt::Display for ParseSanError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("invalid SAN syntax") f.write_str("invalid SAN syntax")
} }
} }
impl std::error::Error for ParseSanError {} impl core::error::Error for ParseSanError {}
/// An error while converting [`San`] notation to a playable [`Move`]. /// An error while converting [`San`] notation to a playable [`Move`].
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
@ -120,8 +120,8 @@ pub enum InvalidSan {
/// There is more than one move on the position that matches the SAN notation. /// There is more than one move on the position that matches the SAN notation.
Ambiguous, Ambiguous,
} }
impl std::fmt::Display for InvalidSan { impl core::fmt::Display for InvalidSan {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let details = match self { let details = match self {
Self::Illegal => "illegal move", Self::Illegal => "illegal move",
Self::Ambiguous => "ambiguous move", Self::Ambiguous => "ambiguous move",
@ -129,7 +129,7 @@ impl std::fmt::Display for InvalidSan {
write!(f, "invalid SAN ({details})") write!(f, "invalid SAN ({details})")
} }
} }
impl std::error::Error for InvalidSan {} impl core::error::Error for InvalidSan {}
impl San { impl San {
/// Tries to convert SAN notation to a playable move. /// Tries to convert SAN notation to a playable move.

View file

@ -7,6 +7,8 @@ use crate::board::*;
use crate::lookup; use crate::lookup;
use crate::position::*; use crate::position::*;
use alloc::string::String;
/// **A builder type for chess positions.** /// **A builder type for chess positions.**
/// ///
/// This type is useful to edit a position without having to ensure it stays legal at every step. /// This type is useful to edit a position without having to ensure it stays legal at every step.
@ -152,9 +154,9 @@ impl Setup {
} }
/// Writes the text record of the position. /// Writes the text record of the position.
pub fn write_text_record<W>(&self, w: &mut W) -> std::fmt::Result pub fn write_text_record<W>(&self, w: &mut W) -> core::fmt::Result
where where
W: std::fmt::Write, W: core::fmt::Write,
{ {
for rank in Rank::all().into_iter().rev() { for rank in Rank::all().into_iter().rev() {
let mut count = 0; let mut count = 0;
@ -526,14 +528,14 @@ impl TryFrom<Setup> for Position {
} }
pub(crate) struct TextRecord<'a>(pub(crate) &'a Setup); pub(crate) struct TextRecord<'a>(pub(crate) &'a Setup);
impl<'a> std::fmt::Display for TextRecord<'a> { impl<'a> core::fmt::Display for TextRecord<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0.write_text_record(f) self.0.write_text_record(f)
} }
} }
impl<'a> std::fmt::Debug for TextRecord<'a> { impl<'a> core::fmt::Debug for TextRecord<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use std::fmt::Write; use core::fmt::Write;
f.write_char('"')?; f.write_char('"')?;
self.0.write_text_record(f)?; self.0.write_text_record(f)?;
f.write_char('"')?; f.write_char('"')?;
@ -541,8 +543,8 @@ impl<'a> std::fmt::Debug for TextRecord<'a> {
} }
} }
impl std::fmt::Debug for Setup { impl core::fmt::Debug for Setup {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
f.debug_tuple("Setup").field(&TextRecord(&self)).finish() f.debug_tuple("Setup").field(&TextRecord(&self)).finish()
} }
} }
@ -555,9 +557,9 @@ pub struct IllegalPosition {
pub setup: Setup, pub setup: Setup,
pub reasons: IllegalPositionReasons, pub reasons: IllegalPositionReasons,
} }
impl std::fmt::Display for IllegalPosition { impl core::fmt::Display for IllegalPosition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
use std::fmt::Write; use core::fmt::Write;
let setup = &self.setup; let setup = &self.setup;
write!(f, "`{}` is illegal:", &TextRecord(setup))?; write!(f, "`{}` is illegal:", &TextRecord(setup))?;
let mut first = true; let mut first = true;
@ -572,14 +574,14 @@ impl std::fmt::Display for IllegalPosition {
Ok(()) Ok(())
} }
} }
impl std::error::Error for IllegalPosition {} impl core::error::Error for IllegalPosition {}
/// A set of [`IllegalPositionReason`]s. /// A set of [`IllegalPositionReason`]s.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct IllegalPositionReasons(u8); pub struct IllegalPositionReasons(u8);
impl std::fmt::Debug for IllegalPositionReasons { impl core::fmt::Debug for IllegalPositionReasons {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_list().entries(*self).finish() f.debug_list().entries(*self).finish()
} }
} }
@ -607,7 +609,7 @@ impl Iterator for IllegalPositionReasons {
} else { } else {
let reason = 1 << self.0.trailing_zeros(); let reason = 1 << self.0.trailing_zeros();
self.0 &= !reason; self.0 &= !reason;
Some(unsafe { std::mem::transmute::<u8, IllegalPositionReason>(reason) }) Some(unsafe { core::mem::transmute::<u8, IllegalPositionReason>(reason) })
} }
} }
} }
@ -659,8 +661,8 @@ impl IllegalPositionReason {
} }
} }
impl std::fmt::Display for IllegalPositionReason { impl core::fmt::Display for IllegalPositionReason {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.to_str()) f.write_str(self.to_str())
} }
} }
@ -670,9 +672,9 @@ impl std::fmt::Display for IllegalPositionReason {
pub struct ParseRecordError { pub struct ParseRecordError {
pub byte: usize, pub byte: usize,
} }
impl std::fmt::Display for ParseRecordError { impl core::fmt::Display for ParseRecordError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "invalid text record (at byte {})", self.byte) write!(f, "invalid text record (at byte {})", self.byte)
} }
} }
impl std::error::Error for ParseRecordError {} impl core::error::Error for ParseRecordError {}

View file

@ -22,9 +22,9 @@ pub struct UciMove {
pub promotion: Option<Role>, pub promotion: Option<Role>,
} }
impl std::fmt::Display for UciMove { impl core::fmt::Display for UciMove {
#[inline] #[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}{}", self.from, self.to)?; write!(f, "{}{}", self.from, self.to)?;
if let Some(promotion) = self.promotion { if let Some(promotion) = self.promotion {
write!(f, "{}", promotion.to_char_lowercase())?; write!(f, "{}", promotion.to_char_lowercase())?;
@ -33,13 +33,13 @@ impl std::fmt::Display for UciMove {
} }
} }
impl std::fmt::Debug for UciMove { impl core::fmt::Debug for UciMove {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
f.debug_tuple("UciMove").field(&self.to_string()).finish() write!(f, "UciMove(\"{self}\")")
} }
} }
impl std::str::FromStr for UciMove { impl core::str::FromStr for UciMove {
type Err = ParseUciMoveError; type Err = ParseUciMoveError;
#[inline] #[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -50,12 +50,12 @@ impl std::str::FromStr for UciMove {
/// A syntax error when parsing a [`UciMove`]. /// A syntax error when parsing a [`UciMove`].
#[derive(Debug)] #[derive(Debug)]
pub struct ParseUciMoveError; pub struct ParseUciMoveError;
impl std::fmt::Display for ParseUciMoveError { impl core::fmt::Display for ParseUciMoveError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("invalid UCI notation") f.write_str("invalid UCI notation")
} }
} }
impl std::error::Error for ParseUciMoveError {} impl core::error::Error for ParseUciMoveError {}
/// An error when converting [`UciMove`] notation to a playable [`Move`]. /// An error when converting [`UciMove`] notation to a playable [`Move`].
#[derive(Debug)] #[derive(Debug)]
@ -63,12 +63,12 @@ pub enum InvalidUciMove {
/// The is no move on the position that matches the UCI notation. /// The is no move on the position that matches the UCI notation.
Illegal, Illegal,
} }
impl std::fmt::Display for InvalidUciMove { impl core::fmt::Display for InvalidUciMove {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("illegal UCI move") f.write_str("illegal UCI move")
} }
} }
impl std::error::Error for InvalidUciMove {} impl core::error::Error for InvalidUciMove {}
impl UciMove { impl UciMove {
/// Tries to convert UCI notation to a playable move. /// Tries to convert UCI notation to a playable move.