use std::ops::Not;
use super::{
ALWAYS_FALSE_NAME,
ALWAYS_TRUE_NAME,
BiPredicate,
BiPredicateFn,
RcBiPredicate,
impl_box_conversions,
impl_box_predicate_methods,
impl_predicate_common_methods,
impl_predicate_debug_display,
};
pub struct BoxBiPredicate<T, U> {
pub(super) function: Box<BiPredicateFn<T, U>>,
pub(super) name: Option<String>,
}
impl<T, U> BoxBiPredicate<T, U> {
impl_predicate_common_methods!(
BoxBiPredicate<T, U>,
(Fn(&T, &U) -> bool + 'static),
|f| Box::new(f)
);
impl_box_predicate_methods!(BoxBiPredicate<T, U>);
}
impl<T, U> Not for BoxBiPredicate<T, U>
where
T: 'static,
U: 'static,
{
type Output = BoxBiPredicate<T, U>;
fn not(self) -> Self::Output {
BoxBiPredicate::new(move |first, second| !(self.function)(first, second))
}
}
impl_predicate_debug_display!(BoxBiPredicate<T, U>);
impl<T, U> BiPredicate<T, U> for BoxBiPredicate<T, U> {
fn test(&self, first: &T, second: &U) -> bool {
(self.function)(first, second)
}
impl_box_conversions!(
BoxBiPredicate<T, U>,
RcBiPredicate,
Fn(&T, &U) -> bool
);
}