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_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_predicate;
pub use arc_stateful_predicate::ArcStatefulPredicate;
mod box_stateful_predicate;
pub use box_stateful_predicate::BoxStatefulPredicate;
mod fn_stateful_predicate_ops;
pub use fn_stateful_predicate_ops::FnStatefulPredicateOps;
mod rc_stateful_predicate;
pub use rc_stateful_predicate::RcStatefulPredicate;
pub trait StatefulPredicate<T> {
fn test(&mut self, value: &T) -> bool;
fn into_box(mut self) -> BoxStatefulPredicate<T>
where
Self: Sized + 'static,
{
BoxStatefulPredicate::new(move |value: &T| self.test(value))
}
fn into_rc(mut self) -> RcStatefulPredicate<T>
where
Self: Sized + 'static,
{
RcStatefulPredicate::new(move |value: &T| self.test(value))
}
fn into_arc(mut self) -> ArcStatefulPredicate<T>
where
Self: Sized + Send + 'static,
{
ArcStatefulPredicate::new(move |value: &T| self.test(value))
}
fn into_fn(mut self) -> impl FnMut(&T) -> bool
where
Self: Sized + 'static,
{
move |value: &T| self.test(value)
}
fn to_box(&self) -> BoxStatefulPredicate<T>
where
Self: Clone + Sized + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcStatefulPredicate<T>
where
Self: Clone + Sized + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcStatefulPredicate<T>
where
Self: Clone + Sized + Send + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl FnMut(&T) -> bool
where
Self: Clone + Sized + 'static,
{
let mut predicate = self.clone();
move |value: &T| predicate.test(value)
}
}