#![allow(unused_imports)]
use super::*;
pub struct BoxRunnableWith<T, E> {
pub(super) function: Box<dyn FnMut(&mut T) -> Result<(), E>>,
pub(super) name: Option<String>,
}
impl<T, E> BoxRunnableWith<T, E> {
impl_common_new_methods!(
(FnMut(&mut T) -> Result<(), E> + 'static),
|function| Box::new(function),
"runnable-with"
);
impl_common_name_methods!("runnable-with");
#[inline]
pub fn and_then<N>(self, next: N) -> BoxRunnableWith<T, E>
where
N: RunnableWith<T, E> + 'static,
T: 'static,
E: 'static,
{
let name = self.name;
let mut function = self.function;
let mut next = next;
BoxRunnableWith::new_with_optional_name(
move |input| {
function(input)?;
next.run_with(input)
},
name,
)
}
#[inline]
pub fn then_callable_with<R, C>(self, callable: C) -> BoxCallableWith<T, R, E>
where
C: crate::tasks::callable_with::CallableWith<T, R, E> + 'static,
T: 'static,
R: 'static,
E: 'static,
{
let name = self.name;
let mut function = self.function;
let mut callable = callable;
BoxCallableWith::new_with_optional_name(
move |input| {
function(input)?;
callable.call_with(input)
},
name,
)
}
}
impl<T, E> RunnableWith<T, E> for BoxRunnableWith<T, E> {
#[inline]
fn run_with(&mut self, input: &mut T) -> Result<(), E> {
(self.function)(input)
}
impl_box_conversions!(
BoxRunnableWith<T, E>,
RcRunnableWith,
FnMut(&mut T) -> Result<(), E>
);
#[inline]
fn into_callable_with(self) -> BoxCallableWith<T, (), E>
where
Self: Sized + 'static,
{
let name = self.name;
let mut function = self.function;
BoxCallableWith::new_with_optional_name(
move |input| {
function(input)?;
Ok(())
},
name,
)
}
}