use std::ops::Not;
use super::{
ALWAYS_FALSE_NAME,
ALWAYS_TRUE_NAME,
Arc,
BiPredicate,
BoxBiPredicate,
RcBiPredicate,
SendSyncBiPredicateFn,
impl_arc_conversions,
impl_closure_trait,
impl_predicate_clone,
impl_predicate_common_methods,
impl_predicate_debug_display,
impl_shared_predicate_methods,
};
pub struct ArcBiPredicate<T, U> {
pub(super) function: Arc<SendSyncBiPredicateFn<T, U>>,
pub(super) name: Option<String>,
}
impl<T, U> ArcBiPredicate<T, U> {
impl_predicate_common_methods!(
ArcBiPredicate<T, U>,
(Fn(&T, &U) -> bool + Send + Sync + 'static),
|f| Arc::new(f)
);
impl_shared_predicate_methods!(
ArcBiPredicate<T, U>,
Send + Sync + 'static
);
}
impl<T, U> Not for ArcBiPredicate<T, U>
where
T: 'static,
U: 'static,
{
type Output = ArcBiPredicate<T, U>;
fn not(self) -> Self::Output {
let function = self.function;
ArcBiPredicate::new(move |first, second| !function(first, second))
}
}
impl<T, U> Not for &ArcBiPredicate<T, U>
where
T: 'static,
U: 'static,
{
type Output = ArcBiPredicate<T, U>;
fn not(self) -> Self::Output {
let function = self.function.clone();
ArcBiPredicate::new(move |first, second| !function(first, second))
}
}
impl_predicate_clone!(ArcBiPredicate<T, U>);
impl_predicate_debug_display!(ArcBiPredicate<T, U>);
impl<T, U> BiPredicate<T, U> for ArcBiPredicate<T, U> {
fn test(&self, first: &T, second: &U) -> bool {
(self.function)(first, second)
}
impl_arc_conversions!(
ArcBiPredicate<T, U>,
BoxBiPredicate,
RcBiPredicate,
Fn(first: &T, second: &U) -> bool
);
}
impl_closure_trait!(
BiPredicate<T, U>,
test,
Fn(first: &T, second: &U) -> bool
);