use std::ops::Not;
use {
super::ALWAYS_FALSE_NAME,
super::ALWAYS_TRUE_NAME,
super::BiPredicateFn,
crate::BiPredicate,
crate::predicates::macros::impl_box_predicate_methods,
crate::predicates::macros::impl_predicate_common_methods,
crate::predicates::macros::impl_predicate_debug_display,
};
#[must_use = "callback wrappers do nothing unless stored or invoked"]
pub struct BoxBiPredicate<T, U> {
pub(super) function: Box<BiPredicateFn<T, U>>,
pub(super) metadata: crate::internal::CallbackMetadata,
}
impl<T, U> BoxBiPredicate<T, U> {
impl_predicate_common_methods!(
BoxBiPredicate<T, U>,
semantic (BiPredicate<T, U> + 'static),
|predicate| move |first: &T, second: &U| predicate.test(first, second),
|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 {
let metadata = self.metadata;
let function = self.function;
BoxBiPredicate::new_with_metadata(
move |first: &T, second: &U| !function(first, second),
metadata,
)
}
}
impl_predicate_debug_display!(BoxBiPredicate<T, U>);
impl<T, U> BiPredicate<T, U> for BoxBiPredicate<T, U> {
#[inline(always)]
fn test(&self, first: &T, second: &U) -> bool {
(self.function)(first, second)
}
}