use std::rc::Rc;
use std::sync::Arc;
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_closure_trait,
impl_rc_conversions,
};
use crate::predicates::predicate::{
ArcPredicate,
BoxPredicate,
Predicate,
RcPredicate,
};
mod box_function;
pub use box_function::BoxFunction;
mod rc_function;
pub use rc_function::RcFunction;
mod arc_function;
pub use arc_function::ArcFunction;
mod box_conditional_function;
pub use box_conditional_function::BoxConditionalFunction;
mod rc_conditional_function;
pub use rc_conditional_function::RcConditionalFunction;
mod arc_conditional_function;
pub use arc_conditional_function::ArcConditionalFunction;
mod fn_function_ops;
pub use fn_function_ops::FnFunctionOps;
pub trait Function<T, R> {
fn apply(&self, t: &T) -> R;
fn into_box(self) -> BoxFunction<T, R>
where
Self: Sized + 'static,
{
BoxFunction::new(move |t| self.apply(t))
}
fn into_rc(self) -> RcFunction<T, R>
where
Self: Sized + 'static,
{
RcFunction::new(move |t| self.apply(t))
}
fn into_arc(self) -> ArcFunction<T, R>
where
Self: Sized + Send + Sync + 'static,
{
ArcFunction::new(move |t| self.apply(t))
}
fn into_fn(self) -> impl Fn(&T) -> R
where
Self: Sized + 'static,
{
move |t| self.apply(t)
}
fn into_once(self) -> BoxFunctionOnce<T, R>
where
Self: Sized + 'static,
{
BoxFunctionOnce::new(move |t| self.apply(t))
}
fn to_box(&self) -> BoxFunction<T, R>
where
Self: Clone + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcFunction<T, R>
where
Self: Clone + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcFunction<T, R>
where
Self: Clone + Send + Sync + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl Fn(&T) -> R
where
Self: Clone + 'static,
{
self.clone().into_fn()
}
fn to_once(&self) -> BoxFunctionOnce<T, R>
where
Self: Clone + 'static,
{
self.clone().into_once()
}
}