use crate::{
functions::macros::impl_function_debug_display,
macros::{
impl_box_once_conversions,
impl_common_name_methods,
impl_common_new_methods,
},
suppliers::supplier_once::SupplierOnce,
tasks::runnable_once::{
BoxRunnableOnce,
LocalBoxRunnableOnce,
},
};
mod box_callable_once;
pub use box_callable_once::BoxCallableOnce;
mod local_box_callable_once;
pub use local_box_callable_once::LocalBoxCallableOnce;
pub trait CallableOnce<R, E> {
fn call(self) -> Result<R, E>;
fn into_box(self) -> BoxCallableOnce<R, E>
where
Self: Sized + Send + 'static,
{
BoxCallableOnce::new(move || self.call())
}
fn into_local_box(self) -> LocalBoxCallableOnce<R, E>
where
Self: Sized + 'static,
{
LocalBoxCallableOnce::new(move || self.call())
}
fn into_fn(self) -> impl FnOnce() -> Result<R, E>
where
Self: Sized + 'static,
{
move || self.call()
}
fn to_box(&self) -> BoxCallableOnce<R, E>
where
Self: Clone + Send + Sized + 'static,
{
self.clone().into_box()
}
fn to_local_box(&self) -> LocalBoxCallableOnce<R, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_local_box()
}
fn to_fn(&self) -> impl FnOnce() -> Result<R, E>
where
Self: Clone + Sized + 'static,
{
self.clone().into_fn()
}
fn into_runnable(self) -> BoxRunnableOnce<E>
where
Self: Sized + Send + 'static,
{
BoxRunnableOnce::new(move || self.call().map(|_| ()))
}
fn into_local_runnable(self) -> LocalBoxRunnableOnce<E>
where
Self: Sized + 'static,
{
LocalBoxRunnableOnce::new(move || self.call().map(|_| ()))
}
}