diff --git a/src/board/color.rs b/src/board/color.rs index 6e828a6..828b1cf 100644 --- a/src/board/color.rs +++ b/src/board/color.rs @@ -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 { + 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;