[board] Implement an infix_op! macro for generating BitBoard operator traits
This commit is contained in:
parent
50a6be2f72
commit
51a265172b
1 changed files with 16 additions and 31 deletions
|
@ -95,23 +95,26 @@ impl fmt::Debug for BitBoard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BitAnd for BitBoard {
|
macro_rules! infix_op {
|
||||||
type Output = BitBoard;
|
($trait_type:ident, $func_name:ident, $left_type:ty, $right_type:ty, $op:tt) => {
|
||||||
|
impl $trait_type<$right_type> for $left_type {
|
||||||
|
type Output = BitBoard;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bitand(self, rhs: Self) -> Self {
|
fn $func_name(self, rhs: $right_type) -> Self::Output {
|
||||||
BitBoard(self.0 & rhs.0)
|
BitBoard(self.0 $op rhs.0)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BitAnd<&BitBoard> for BitBoard {
|
infix_op!(BitAnd, bitand, BitBoard, BitBoard, &);
|
||||||
type Output = BitBoard;
|
infix_op!(BitAnd, bitand, &BitBoard, BitBoard, &);
|
||||||
|
infix_op!(BitAnd, bitand, BitBoard, &BitBoard, &);
|
||||||
|
|
||||||
#[inline]
|
infix_op!(BitOr, bitor, BitBoard, BitBoard, |);
|
||||||
fn bitand(self, rhs: &Self) -> Self {
|
infix_op!(BitOr, bitor, &BitBoard, BitBoard, |);
|
||||||
BitBoard(self.0 & rhs.0)
|
infix_op!(BitOr, bitor, BitBoard, &BitBoard, |);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Not for BitBoard {
|
impl Not for BitBoard {
|
||||||
type Output = BitBoard;
|
type Output = BitBoard;
|
||||||
|
@ -131,24 +134,6 @@ impl Not for &BitBoard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BitOr for BitBoard {
|
|
||||||
type Output = BitBoard;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn bitor(self, rhs: Self) -> Self {
|
|
||||||
BitBoard(self.0 | rhs.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BitOr<&BitBoard> for BitBoard {
|
|
||||||
type Output = BitBoard;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn bitor(self, rhs: &Self) -> Self {
|
|
||||||
BitBoard(self.0 | rhs.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue