Simplify 'TryInto<Square>' for 'Bitboard'

This commit is contained in:
Bruno BELANYI 2024-04-14 16:09:58 +01:00
parent ed38c6c12d
commit 524e3b2c76

View file

@ -116,12 +116,10 @@ impl TryInto<Square> for Bitboard {
type Error = IntoSquareError; type Error = IntoSquareError;
fn try_into(self) -> Result<Square, Self::Error> { fn try_into(self) -> Result<Square, Self::Error> {
let index = match self.count() { if self.has_more_than_one() {
1 => self.0.trailing_zeros() as usize, return Err(IntoSquareError::TooManySquares);
0 => return Err(IntoSquareError::EmptyBoard), }
_ => return Err(IntoSquareError::TooManySquares), self.any_square().ok_or(IntoSquareError::EmptyBoard)
};
Ok(Square::from_index(index))
} }
} }