Add 'TryInto<Square>' for 'Bitboard'

This commit is contained in:
Bruno BELANYI 2022-07-29 19:26:31 +02:00
parent bc67ee3e9a
commit 6976c60fe6
2 changed files with 55 additions and 0 deletions

View file

@ -0,0 +1,19 @@
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum IntoSquareError {
/// The board is empty.
EmptyBoard,
/// The board contains more than one square.
TooManySquares,
}
impl std::fmt::Display for IntoSquareError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let error_msg = match self {
Self::EmptyBoard => "The board is empty",
Self::TooManySquares => "The board contains more than one square",
};
write!(f, "{}", error_msg)
}
}
impl std::error::Error for IntoSquareError {}