#![allow(unused_imports)]
use super::*;
pub struct ArcStatefulFunction<T, R> {
pub(super) function: ArcStatefulFn<T, R>,
pub(super) name: Option<String>,
}
type ArcStatefulFn<T, R> = Arc<Mutex<dyn FnMut(&T) -> R + Send + 'static>>;
impl<T, R> ArcStatefulFunction<T, R> {
impl_function_common_methods!(
ArcStatefulFunction<T, R>,
(FnMut(&T) -> R + Send + 'static),
|f| Arc::new(Mutex::new(f))
);
impl_shared_function_methods!(
ArcStatefulFunction<T, R>,
ArcConditionalStatefulFunction,
into_arc,
StatefulFunction,
Send + Sync + 'static
);
}
impl_function_constant_method!(ArcStatefulFunction<T, R>, Send + Sync + 'static);
impl_function_identity_method!(ArcStatefulFunction<T, T>);
impl_function_clone!(ArcStatefulFunction<T, R>);
impl_function_debug_display!(ArcStatefulFunction<T, R>);
impl<T, R> StatefulFunction<T, R> for ArcStatefulFunction<T, R> {
fn apply(&mut self, t: &T) -> R {
(self.function.lock())(t)
}
impl_arc_conversions!(
ArcStatefulFunction<T, R>,
BoxStatefulFunction,
RcStatefulFunction,
BoxFunctionOnce,
FnMut(t: &T) -> R
);
}
impl<F, T, R> StatefulFunction<T, R> for F
where
F: FnMut(&T) -> R,
{
fn apply(&mut self, t: &T) -> R {
self(t)
}
fn into_box(self) -> BoxStatefulFunction<T, R>
where
Self: Sized + 'static,
{
BoxStatefulFunction::new(self)
}
fn into_rc(self) -> RcStatefulFunction<T, R>
where
Self: Sized + 'static,
{
RcStatefulFunction::new(self)
}
fn into_arc(self) -> ArcStatefulFunction<T, R>
where
Self: Sized + Send + 'static,
{
ArcStatefulFunction::new(self)
}
fn into_fn(self) -> impl FnMut(&T) -> R
where
Self: Sized + 'static,
{
self
}
fn to_box(&self) -> BoxStatefulFunction<T, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcStatefulFunction<T, R>
where
Self: Sized + Clone + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcStatefulFunction<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()
}
fn into_once(self) -> BoxFunctionOnce<T, R>
where
Self: Sized + 'static,
{
BoxFunctionOnce::new(self)
}
fn to_once(&self) -> BoxFunctionOnce<T, R>
where
Self: Sized + Clone + 'static,
{
BoxFunctionOnce::new(self.clone())
}
}