From 524e3b2c767334b206354d7fc2f0023d92e37995 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 14 Apr 2024 16:09:58 +0100 Subject: [PATCH] Simplify 'TryInto' for 'Bitboard' --- src/board/bitboard/mod.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/board/bitboard/mod.rs b/src/board/bitboard/mod.rs index 81762ed..3cb9d7b 100644 --- a/src/board/bitboard/mod.rs +++ b/src/board/bitboard/mod.rs @@ -116,12 +116,10 @@ impl TryInto for Bitboard { type Error = IntoSquareError; fn try_into(self) -> Result { - let index = match self.count() { - 1 => self.0.trailing_zeros() as usize, - 0 => return Err(IntoSquareError::EmptyBoard), - _ => return Err(IntoSquareError::TooManySquares), - }; - Ok(Square::from_index(index)) + if self.has_more_than_one() { + return Err(IntoSquareError::TooManySquares); + } + self.any_square().ok_or(IntoSquareError::EmptyBoard) } }