pub trait CallableOnce<R, E> {
// Required method
fn call(self) -> Result<R, E>;
// Provided methods
fn into_box(self) -> BoxCallableOnce<R, E>
where Self: Sized + Send + 'static { ... }
fn into_local_box(self) -> LocalBoxCallableOnce<R, E>
where Self: Sized + 'static { ... }
fn into_fn(self) -> impl FnOnce() -> Result<R, E>
where Self: Sized + 'static { ... }
fn to_box(&self) -> BoxCallableOnce<R, E>
where Self: Clone + Send + Sized + 'static { ... }
fn to_local_box(&self) -> LocalBoxCallableOnce<R, E>
where Self: Clone + Sized + 'static { ... }
fn to_fn(&self) -> impl FnOnce() -> Result<R, E>
where Self: Clone + Sized + 'static { ... }
fn into_runnable(self) -> BoxRunnableOnce<E>
where Self: Sized + Send + 'static { ... }
fn into_local_runnable(self) -> LocalBoxRunnableOnce<E>
where Self: Sized + 'static { ... }
}Expand description
A fallible one-time computation.
Conceptually this matches FnOnce() -> Result<R, E>: call consumes self
and returns Result<R, E>, but the surface uses task-oriented naming and
helpers instead of closure types. It is a semantic specialization of
SupplierOnce<Result<R, E>> for executable computations and deferred tasks.
Choose CallableOnce when callers need the success value R. When only
success or failure matters, use RunnableOnce,
whose success type is ().
§Type Parameters
R- The success value returned by the computation.E- The error value returned when the computation fails.
§Examples
use qubit_function::{CallableOnce, BoxCallableOnce};
let task = || Ok::<i32, String>(21 * 2);
assert_eq!(task.call(), Ok(42));Required Methods§
Provided Methods§
Sourcefn into_box(self) -> BoxCallableOnce<R, E>
fn into_box(self) -> BoxCallableOnce<R, E>
Converts this callable into a boxed callable.
§Returns
A BoxCallableOnce<R, E> that executes this callable when call() is
invoked.
Sourcefn into_local_box(self) -> LocalBoxCallableOnce<R, E>where
Self: Sized + 'static,
fn into_local_box(self) -> LocalBoxCallableOnce<R, E>where
Self: Sized + 'static,
Converts this callable into a local boxed callable.
§Returns
A LocalBoxCallableOnce<R, E> that may hold non-Send captures and
must be executed on the local thread.
Sourcefn to_box(&self) -> BoxCallableOnce<R, E>
fn to_box(&self) -> BoxCallableOnce<R, E>
Converts this callable into a boxed callable without consuming self.
The method clones self and boxes the clone. Use this for cloneable
callable values that need to be reused after boxing.
§Returns
A new BoxCallableOnce<R, E> built from a clone of this callable.
Sourcefn to_local_box(&self) -> LocalBoxCallableOnce<R, E>
fn to_local_box(&self) -> LocalBoxCallableOnce<R, E>
Converts this callable into a local boxed callable without consuming
self.
The method clones self and boxes the clone without requiring Send.
§Returns
A new LocalBoxCallableOnce<R, E> built from a clone of this callable.
Sourcefn to_fn(&self) -> impl FnOnce() -> Result<R, E>
fn to_fn(&self) -> impl FnOnce() -> Result<R, E>
Converts this callable into a closure without consuming self.
The method clones self and returns a one-time closure that executes
the clone.
§Returns
A closure implementing FnOnce() -> Result<R, E>.
Sourcefn into_runnable(self) -> BoxRunnableOnce<E>
fn into_runnable(self) -> BoxRunnableOnce<E>
Converts this callable into a runnable by discarding the success value.
The returned runnable preserves errors and maps any Ok(R) to
Ok(()).
§Returns
A BoxRunnableOnce<E> that executes this callable and discards its
success value.
Sourcefn into_local_runnable(self) -> LocalBoxRunnableOnce<E>where
Self: Sized + 'static,
fn into_local_runnable(self) -> LocalBoxRunnableOnce<E>where
Self: Sized + 'static,
Converts this callable into a local runnable by discarding the success value.
§Returns
A LocalBoxRunnableOnce<E> that may hold non-Send captures and maps
any Ok(R) to Ok(()).