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

@ -48,8 +48,8 @@ pub(crate) enum SanSuffix {
Checkmate,
}
impl std::fmt::Display for San {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Display for San {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self.inner {
SanInner::Castle(CastlingSide::Short) => write!(f, "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 {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_tuple("San").field(&self.to_string()).finish()
impl core::fmt::Debug for San {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "San(\"{self}\")")
}
}
impl std::str::FromStr for San {
impl core::str::FromStr for San {
type Err = ParseSanError;
#[inline]
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.
#[derive(Debug)]
pub struct ParseSanError;
impl std::fmt::Display for ParseSanError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Display for ParseSanError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
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`].
#[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.
Ambiguous,
}
impl std::fmt::Display for InvalidSan {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Display for InvalidSan {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let details = match self {
Self::Illegal => "illegal move",
Self::Ambiguous => "ambiguous move",
@ -129,7 +129,7 @@ impl std::fmt::Display for InvalidSan {
write!(f, "invalid SAN ({details})")
}
}
impl std::error::Error for InvalidSan {}
impl core::error::Error for InvalidSan {}
impl San {
/// Tries to convert SAN notation to a playable move.