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::predicate::{
ArcPredicate,
BoxPredicate,
Predicate,
RcPredicate,
};
use crate::transformers::{
macros::{
impl_box_conditional_transformer,
impl_box_transformer_methods,
impl_conditional_transformer_clone,
impl_conditional_transformer_debug_display,
impl_shared_conditional_transformer,
impl_shared_transformer_methods,
impl_transformer_clone,
impl_transformer_common_methods,
impl_transformer_constant_method,
impl_transformer_debug_display,
},
transformer_once::BoxTransformerOnce,
};
mod box_stateful_transformer;
pub use box_stateful_transformer::BoxStatefulTransformer;
mod rc_stateful_transformer;
pub use rc_stateful_transformer::RcStatefulTransformer;
mod arc_stateful_transformer;
pub use arc_stateful_transformer::ArcStatefulTransformer;
mod fn_stateful_transformer_ops;
pub use fn_stateful_transformer_ops::FnStatefulTransformerOps;
mod box_conditional_stateful_transformer;
pub use box_conditional_stateful_transformer::BoxConditionalStatefulTransformer;
mod rc_conditional_stateful_transformer;
pub use rc_conditional_stateful_transformer::RcConditionalStatefulTransformer;
mod arc_conditional_stateful_transformer;
pub use arc_conditional_stateful_transformer::ArcConditionalStatefulTransformer;
pub trait StatefulTransformer<T, R> {
fn apply(&mut self, input: T) -> R;
fn into_box(self) -> BoxStatefulTransformer<T, R>
where
Self: Sized + 'static,
{
let mut transformer = self;
BoxStatefulTransformer::new(move |t| transformer.apply(t))
}
fn into_rc(self) -> RcStatefulTransformer<T, R>
where
Self: Sized + 'static,
{
let mut transformer = self;
RcStatefulTransformer::new(move |t| transformer.apply(t))
}
fn into_arc(self) -> ArcStatefulTransformer<T, R>
where
Self: Sized + Send + 'static,
{
let mut transformer = self;
ArcStatefulTransformer::new(move |t| transformer.apply(t))
}
fn into_fn(self) -> impl FnMut(T) -> R
where
Self: Sized + 'static,
{
let mut transformer = self;
move |t| transformer.apply(t)
}
fn into_mut_fn(self) -> impl FnMut(T) -> R
where
Self: Sized + 'static,
{
self.into_fn()
}
fn into_once(self) -> BoxTransformerOnce<T, R>
where
Self: Sized + 'static,
{
let mut transformer = self;
BoxTransformerOnce::new(move |t| transformer.apply(t))
}
fn to_box(&self) -> BoxStatefulTransformer<T, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcStatefulTransformer<T, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcStatefulTransformer<T, R>
where
Self: Sized + Clone + Send + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl FnMut(T) -> R
where
Self: Sized + Clone + 'static,
{
self.clone().into_fn()
}
fn to_mut_fn(&self) -> impl FnMut(T) -> R
where
Self: Sized + Clone + 'static,
{
self.to_fn()
}
fn to_once(&self) -> BoxTransformerOnce<T, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_once()
}
}