use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use parking_lot::Mutex;
use crate::functions::{
function_once::BoxFunctionOnce,
macros::{
impl_box_conditional_function,
impl_box_function_methods,
impl_conditional_function_clone,
impl_conditional_function_debug_display,
impl_fn_ops_trait,
impl_function_clone,
impl_function_common_methods,
impl_function_constant_method,
impl_function_debug_display,
impl_function_identity_method,
impl_shared_conditional_function,
impl_shared_function_methods,
},
};
use crate::macros::{
impl_arc_conversions,
impl_box_conversions,
impl_rc_conversions,
};
use crate::predicates::predicate::{
ArcPredicate,
BoxPredicate,
Predicate,
RcPredicate,
};
mod box_stateful_function;
pub use box_stateful_function::BoxStatefulFunction;
mod rc_stateful_function;
pub use rc_stateful_function::RcStatefulFunction;
mod arc_stateful_function;
pub use arc_stateful_function::ArcStatefulFunction;
mod box_conditional_stateful_function;
pub use box_conditional_stateful_function::BoxConditionalStatefulFunction;
mod rc_conditional_stateful_function;
pub use rc_conditional_stateful_function::RcConditionalStatefulFunction;
mod arc_conditional_stateful_function;
pub use arc_conditional_stateful_function::ArcConditionalStatefulFunction;
mod fn_stateful_function_ops;
pub use fn_stateful_function_ops::FnStatefulFunctionOps;
pub trait StatefulFunction<T, R> {
fn apply(&mut self, t: &T) -> R;
fn into_box(mut self) -> BoxStatefulFunction<T, R>
where
Self: Sized + 'static,
{
BoxStatefulFunction::new(move |t| self.apply(t))
}
fn into_rc(mut self) -> RcStatefulFunction<T, R>
where
Self: Sized + 'static,
{
RcStatefulFunction::new(move |t| self.apply(t))
}
fn into_arc(mut self) -> ArcStatefulFunction<T, R>
where
Self: Sized + Send + 'static,
{
ArcStatefulFunction::new(move |t| self.apply(t))
}
fn into_fn(mut self) -> impl FnMut(&T) -> R
where
Self: Sized + 'static,
{
move |t| self.apply(t)
}
fn into_mut_fn(self) -> impl FnMut(&T) -> R
where
Self: Sized + 'static,
{
self.into_fn()
}
fn into_once(mut self) -> BoxFunctionOnce<T, R>
where
Self: Sized + 'static,
{
BoxFunctionOnce::new(move |t| self.apply(t))
}
fn to_box(&self) -> BoxStatefulFunction<T, R>
where
Self: Clone + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcStatefulFunction<T, R>
where
Self: Clone + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcStatefulFunction<T, R>
where
Self: 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) -> BoxFunctionOnce<T, R>
where
Self: Clone + 'static,
{
self.clone().into_once()
}
}