use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use parking_lot::Mutex;
use crate::macros::{
impl_arc_conversions,
impl_box_conversions,
impl_closure_trait,
impl_rc_conversions,
};
use crate::predicates::macros::{
constants::{
ALWAYS_FALSE_NAME,
ALWAYS_TRUE_NAME,
},
impl_predicate_clone,
impl_predicate_common_methods,
impl_predicate_debug_display,
};
mod arc_stateful_bi_predicate;
pub use arc_stateful_bi_predicate::ArcStatefulBiPredicate;
mod box_stateful_bi_predicate;
pub use box_stateful_bi_predicate::BoxStatefulBiPredicate;
mod fn_stateful_bi_predicate_ops;
pub use fn_stateful_bi_predicate_ops::FnStatefulBiPredicateOps;
mod rc_stateful_bi_predicate;
pub use rc_stateful_bi_predicate::RcStatefulBiPredicate;
pub trait StatefulBiPredicate<T, U> {
fn test(&mut self, first: &T, second: &U) -> bool;
fn into_box(mut self) -> BoxStatefulBiPredicate<T, U>
where
Self: Sized + 'static,
{
BoxStatefulBiPredicate::new(move |first: &T, second: &U| self.test(first, second))
}
fn into_rc(mut self) -> RcStatefulBiPredicate<T, U>
where
Self: Sized + 'static,
{
RcStatefulBiPredicate::new(move |first: &T, second: &U| self.test(first, second))
}
fn into_arc(mut self) -> ArcStatefulBiPredicate<T, U>
where
Self: Sized + Send + 'static,
{
ArcStatefulBiPredicate::new(move |first: &T, second: &U| self.test(first, second))
}
fn into_fn(mut self) -> impl FnMut(&T, &U) -> bool
where
Self: Sized + 'static,
{
move |first: &T, second: &U| self.test(first, second)
}
fn to_box(&self) -> BoxStatefulBiPredicate<T, U>
where
Self: Clone + Sized + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcStatefulBiPredicate<T, U>
where
Self: Clone + Sized + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcStatefulBiPredicate<T, U>
where
Self: Clone + Sized + Send + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl FnMut(&T, &U) -> bool
where
Self: Clone + Sized + 'static,
{
let mut predicate = self.clone();
move |first: &T, second: &U| predicate.test(first, second)
}
}