use crate::tasks::callable_with::BoxCallableWith;
mod box_runnable_with;
pub use box_runnable_with::BoxRunnableWith;
mod rc_runnable_with;
pub use rc_runnable_with::RcRunnableWith;
mod arc_runnable_with;
pub use arc_runnable_with::ArcRunnableWith;
pub trait RunnableWith<T, E> {
fn run_with(&mut self, input: &mut T) -> Result<(), E>;
fn into_box(mut self) -> BoxRunnableWith<T, E>
where
Self: Sized + 'static,
{
BoxRunnableWith::new(move |input| self.run_with(input))
}
fn into_rc(mut self) -> RcRunnableWith<T, E>
where
Self: Sized + 'static,
{
RcRunnableWith::new(move |input| self.run_with(input))
}
fn into_arc(mut self) -> ArcRunnableWith<T, E>
where
Self: Sized + Send + 'static,
{
ArcRunnableWith::new(move |input| self.run_with(input))
}
fn into_fn(mut self) -> impl FnMut(&mut T) -> Result<(), E>
where
Self: Sized + 'static,
{
move |input| self.run_with(input)
}
fn to_box(&self) -> BoxRunnableWith<T, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcRunnableWith<T, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcRunnableWith<T, E>
where
Self: Clone + Send + Sized + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl FnMut(&mut T) -> Result<(), E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_fn()
}
fn into_callable_with(mut self) -> BoxCallableWith<T, (), E>
where
Self: Sized + 'static,
{
BoxCallableWith::new(move |input| self.run_with(input))
}
}