use super::{
BoxStatefulBiPredicate,
StatefulBiPredicate,
};
pub trait FnStatefulBiPredicateOps<T, U>: FnMut(&T, &U) -> bool + Sized {
#[inline]
fn and<P>(mut self, mut other: P) -> BoxStatefulBiPredicate<T, U>
where
Self: 'static,
P: StatefulBiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
{
BoxStatefulBiPredicate::new(move |first: &T, second: &U| {
self(first, second) && other.test(first, second)
})
}
#[inline]
fn or<P>(mut self, mut other: P) -> BoxStatefulBiPredicate<T, U>
where
Self: 'static,
P: StatefulBiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
{
BoxStatefulBiPredicate::new(move |first: &T, second: &U| {
self(first, second) || other.test(first, second)
})
}
#[inline]
fn not(mut self) -> BoxStatefulBiPredicate<T, U>
where
Self: 'static,
T: 'static,
U: 'static,
{
BoxStatefulBiPredicate::new(move |first: &T, second: &U| !self(first, second))
}
#[inline]
fn nand<P>(mut self, mut other: P) -> BoxStatefulBiPredicate<T, U>
where
Self: 'static,
P: StatefulBiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
{
BoxStatefulBiPredicate::new(move |first: &T, second: &U| {
!(self(first, second) && other.test(first, second))
})
}
#[inline]
fn xor<P>(mut self, mut other: P) -> BoxStatefulBiPredicate<T, U>
where
Self: 'static,
P: StatefulBiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
{
BoxStatefulBiPredicate::new(move |first: &T, second: &U| {
self(first, second) ^ other.test(first, second)
})
}
#[inline]
fn nor<P>(mut self, mut other: P) -> BoxStatefulBiPredicate<T, U>
where
Self: 'static,
P: StatefulBiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
{
BoxStatefulBiPredicate::new(move |first: &T, second: &U| {
!(self(first, second) || other.test(first, second))
})
}
}
impl<T, U, F> FnStatefulBiPredicateOps<T, U> for F where F: FnMut(&T, &U) -> bool {}