#![allow(unused_imports)]
use super::*;
pub struct ArcStatefulMutatingFunction<T, R> {
pub(super) function: ArcStatefulMutatingFunctionFn<T, R>,
pub(super) name: Option<String>,
}
impl<T, R> ArcStatefulMutatingFunction<T, R> {
impl_function_common_methods!(
ArcStatefulMutatingFunction<T, R>,
(FnMut(&mut T) -> R + Send + 'static),
|f| Arc::new(Mutex::new(f))
);
impl_shared_function_methods!(
ArcStatefulMutatingFunction<T, R>,
ArcConditionalStatefulMutatingFunction,
into_arc,
Function, Send + Sync + 'static
);
}
impl_function_clone!(ArcStatefulMutatingFunction<T, R>);
impl_function_debug_display!(ArcStatefulMutatingFunction<T, R>);
impl_function_identity_method!(ArcStatefulMutatingFunction<T, T>, mutating);
impl<T, R> StatefulMutatingFunction<T, R> for ArcStatefulMutatingFunction<T, R> {
fn apply(&mut self, t: &mut T) -> R {
(self.function.lock())(t)
}
impl_arc_conversions!(
ArcStatefulMutatingFunction<T, R>,
BoxStatefulMutatingFunction,
RcStatefulMutatingFunction,
BoxMutatingFunctionOnce,
FnMut(input: &mut T) -> R
);
}
impl<T, R, F> StatefulMutatingFunction<T, R> for F
where
F: FnMut(&mut T) -> R,
{
fn apply(&mut self, input: &mut T) -> R {
self(input)
}
fn into_box(self) -> BoxStatefulMutatingFunction<T, R>
where
Self: Sized + 'static,
{
BoxStatefulMutatingFunction::new(self)
}
fn into_rc(self) -> RcStatefulMutatingFunction<T, R>
where
Self: Sized + 'static,
{
RcStatefulMutatingFunction::new(self)
}
fn into_arc(self) -> ArcStatefulMutatingFunction<T, R>
where
Self: Sized + Send + 'static,
{
ArcStatefulMutatingFunction::new(self)
}
fn into_fn(self) -> impl FnMut(&mut T) -> R
where
Self: Sized + 'static,
{
self
}
fn to_box(&self) -> BoxStatefulMutatingFunction<T, R>
where
Self: Sized + Clone + 'static,
{
let cloned = self.clone();
BoxStatefulMutatingFunction::new(cloned)
}
fn to_rc(&self) -> RcStatefulMutatingFunction<T, R>
where
Self: Sized + Clone + 'static,
{
let cloned = self.clone();
RcStatefulMutatingFunction::new(cloned)
}
fn to_arc(&self) -> ArcStatefulMutatingFunction<T, R>
where
Self: Sized + Clone + Send + 'static,
{
let cloned = self.clone();
ArcStatefulMutatingFunction::new(cloned)
}
fn to_fn(&self) -> impl FnMut(&mut T) -> R
where
Self: Sized + Clone + 'static,
{
self.clone()
}
fn into_once(self) -> BoxMutatingFunctionOnce<T, R>
where
Self: Sized + 'static,
{
BoxMutatingFunctionOnce::new(self)
}
fn to_once(&self) -> BoxMutatingFunctionOnce<T, R>
where
Self: Sized + Clone + 'static,
{
BoxMutatingFunctionOnce::new(self.clone())
}
}