macro_rules! impl_box_predicate_methods {
(@logical_ops $struct_name:ident < $t:ident >, $trait_name:ident) => {
#[inline]
pub fn and<P>(self, other: P) -> $struct_name<$t>
where
P: $trait_name<$t> + 'static,
$t: 'static,
{
$struct_name::new(move |x| (self.function)(x) && other.test(x))
}
#[inline]
pub fn or<P>(self, other: P) -> $struct_name<$t>
where
P: $trait_name<$t> + 'static,
$t: 'static,
{
$struct_name::new(move |x| (self.function)(x) || other.test(x))
}
#[allow(clippy::should_implement_trait)]
#[inline]
pub fn not(self) -> $struct_name<$t>
where
$t: 'static,
{
$struct_name::new(move |x| !(self.function)(x))
}
#[inline]
pub fn nand<P>(self, other: P) -> $struct_name<$t>
where
P: $trait_name<$t> + 'static,
$t: 'static,
{
$struct_name::new(move |x| !((self.function)(x) && other.test(x)))
}
#[inline]
pub fn xor<P>(self, other: P) -> $struct_name<$t>
where
P: $trait_name<$t> + 'static,
$t: 'static,
{
$struct_name::new(move |x| (self.function)(x) ^ other.test(x))
}
#[inline]
pub fn nor<P>(self, other: P) -> $struct_name<$t>
where
P: $trait_name<$t> + 'static,
$t: 'static,
{
$struct_name::new(move |x| !((self.function)(x) || other.test(x)))
}
};
(@logical_ops $struct_name:ident < $t:ident, $u:ident >, $trait_name:ident) => {
#[inline]
pub fn and<P>(self, other: P) -> $struct_name<$t, $u>
where
P: $trait_name<$t, $u> + 'static,
$t: 'static,
$u: 'static,
{
$struct_name::new(move |x, y| (self.function)(x, y) && other.test(x, y))
}
#[inline]
pub fn or<P>(self, other: P) -> $struct_name<$t, $u>
where
P: $trait_name<$t, $u> + 'static,
$t: 'static,
$u: 'static,
{
$struct_name::new(move |x, y| (self.function)(x, y) || other.test(x, y))
}
#[allow(clippy::should_implement_trait)]
#[inline]
pub fn not(self) -> $struct_name<$t, $u>
where
$t: 'static,
$u: 'static,
{
$struct_name::new(move |x, y| !(self.function)(x, y))
}
#[inline]
pub fn nand<P>(self, other: P) -> $struct_name<$t, $u>
where
P: $trait_name<$t, $u> + 'static,
$t: 'static,
$u: 'static,
{
$struct_name::new(move |x, y| !((self.function)(x, y) && other.test(x, y)))
}
#[inline]
pub fn xor<P>(self, other: P) -> $struct_name<$t, $u>
where
P: $trait_name<$t, $u> + 'static,
$t: 'static,
$u: 'static,
{
$struct_name::new(move |x, y| (self.function)(x, y) ^ other.test(x, y))
}
#[inline]
pub fn nor<P>(self, other: P) -> $struct_name<$t, $u>
where
P: $trait_name<$t, $u> + 'static,
$t: 'static,
$u: 'static,
{
$struct_name::new(move |x, y| !((self.function)(x, y) || other.test(x, y)))
}
};
($struct_name:ident < $t:ident >) => {
impl_box_predicate_methods!(@logical_ops $struct_name<$t>, Predicate);
};
($struct_name:ident < $t:ident, $u:ident >) => {
impl_box_predicate_methods!(@logical_ops $struct_name<$t, $u>, BiPredicate);
};
}
pub(crate) use impl_box_predicate_methods;