use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use parking_lot::Mutex;
use crate::{
macros::{
impl_arc_conversions,
impl_box_conversions,
impl_closure_trait,
impl_common_name_methods,
impl_common_new_methods,
impl_rc_conversions,
},
suppliers::macros::impl_supplier_debug_display,
suppliers::supplier::Supplier,
suppliers::supplier_once::SupplierOnce,
tasks::callable::BoxCallable,
};
mod box_runnable;
pub use box_runnable::BoxRunnable;
mod rc_runnable;
pub use rc_runnable::RcRunnable;
mod arc_runnable;
pub use arc_runnable::ArcRunnable;
pub trait Runnable<E> {
fn run(&mut self) -> Result<(), E>;
fn into_box(mut self) -> BoxRunnable<E>
where
Self: Sized + 'static,
{
BoxRunnable::new(move || self.run())
}
fn into_rc(mut self) -> RcRunnable<E>
where
Self: Sized + 'static,
{
RcRunnable::new(move || self.run())
}
fn into_arc(mut self) -> ArcRunnable<E>
where
Self: Sized + Send + 'static,
{
ArcRunnable::new(move || self.run())
}
fn into_fn(mut self) -> impl FnMut() -> Result<(), E>
where
Self: Sized + 'static,
{
move || self.run()
}
fn to_box(&self) -> BoxRunnable<E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_box()
}
fn to_fn(&self) -> impl FnMut() -> Result<(), E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_fn()
}
fn to_rc(&self) -> RcRunnable<E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcRunnable<E>
where
Self: Clone + Send + Sized + 'static,
{
self.clone().into_arc()
}
fn into_callable(self) -> BoxCallable<(), E>
where
Self: Sized + 'static,
{
let mut runnable = self;
BoxCallable::new(move || runnable.run())
}
}