Add FEN side to move parsing

This commit is contained in:
Bruno BELANYI 2022-07-27 23:40:15 +02:00
parent 611e12c033
commit 6f0e2f732b

View file

@ -1,4 +1,5 @@
use super::{Direction, Rank};
use super::{Direction, FromFen, Rank};
use crate::error::Error;
/// An enum representing the color of a player.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -106,6 +107,20 @@ impl Color {
}
}
/// Convert a side to move segment of a FEN string to a [Color].
impl FromFen for Color {
type Err = Error;
fn from_fen(s: &str) -> Result<Self, Self::Err> {
let res = match s {
"w" => Color::White,
"b" => Color::Black,
_ => return Err(Error::InvalidFen),
};
Ok(res)
}
}
impl std::ops::Not for Color {
type Output = Color;