use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use parking_lot::Mutex;
use crate::{
functions::macros::impl_function_debug_display,
macros::{
impl_arc_conversions,
impl_box_conversions,
impl_closure_trait,
impl_common_name_methods,
impl_common_new_methods,
impl_rc_conversions,
},
suppliers::supplier::Supplier,
tasks::callable_once::BoxCallableOnce,
tasks::runnable::BoxRunnable,
};
mod box_callable;
pub use box_callable::BoxCallable;
mod rc_callable;
pub use rc_callable::RcCallable;
mod arc_callable;
pub use arc_callable::ArcCallable;
pub trait Callable<R, E> {
fn call(&mut self) -> Result<R, E>;
fn into_box(mut self) -> BoxCallable<R, E>
where
Self: Sized + 'static,
{
BoxCallable::new(move || self.call())
}
fn into_rc(mut self) -> RcCallable<R, E>
where
Self: Sized + 'static,
{
RcCallable::new(move || self.call())
}
fn into_arc(mut self) -> ArcCallable<R, E>
where
Self: Sized + Send + 'static,
{
ArcCallable::new(move || self.call())
}
fn into_fn(mut self) -> impl FnMut() -> Result<R, E>
where
Self: Sized + 'static,
{
move || self.call()
}
fn to_box(&self) -> BoxCallable<R, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcCallable<R, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcCallable<R, E>
where
Self: Clone + Send + Sized + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl FnMut() -> Result<R, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_fn()
}
fn into_once(mut self) -> BoxCallableOnce<R, E>
where
Self: Sized + 'static,
{
BoxCallableOnce::new(move || self.call())
}
fn to_once(&self) -> BoxCallableOnce<R, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_once()
}
fn into_runnable(mut self) -> BoxRunnable<E>
where
Self: Sized + 'static,
{
BoxRunnable::new(move || self.call().map(|_| ()))
}
}