Add 'CastleRights::with_{king,queen}_side'

This commit is contained in:
Bruno BELANYI 2022-07-27 23:26:39 +02:00
parent e7e5927902
commit 8102b08cf0

View file

@ -53,6 +53,25 @@ impl CastleRights {
(self.index() & 2) != 0 (self.index() & 2) != 0
} }
/// Add king-side castling rights.
#[inline(always)]
pub fn with_king_side(self) -> Self {
self.add(Self::KingSide)
}
/// Add queen-side castling rights.
#[inline(always)]
pub fn with_queen_side(self) -> Self {
self.add(Self::QueenSide)
}
/// Add some [CastleRights], and return the resulting [CastleRights].
#[inline(always)]
pub fn add(self, to_remove: CastleRights) -> Self {
// SAFETY: we know the value is in-bounds
unsafe { Self::from_index_unchecked(self.index() | to_remove.index()) }
}
/// Remove king-side castling rights. /// Remove king-side castling rights.
#[inline(always)] #[inline(always)]
pub fn without_king_side(self) -> Self { pub fn without_king_side(self) -> Self {