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

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