Add FEN side to move parsing
This commit is contained in:
parent
611e12c033
commit
6f0e2f732b
|
@ -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.
|
/// An enum representing the color of a player.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[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 {
|
impl std::ops::Not for Color {
|
||||||
type Output = Color;
|
type Output = Color;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue