From 6f0e2f732bbcfd92d7f4c0b896bd2fcc1d5db25d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 27 Jul 2022 23:40:15 +0200 Subject: [PATCH] Add FEN side to move parsing --- src/board/color.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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;