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 + 'static { ... }
fn into_fn(self) -> impl FnOnce() -> Result<R, E>
where Self: Sized + 'static { ... }
fn to_box(&self) -> BoxCallableOnce<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 + '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));§Author
Haixing Hu
Required Methods§
Provided Methods§
Sourcefn into_box(self) -> BoxCallableOnce<R, E>where
Self: Sized + 'static,
fn into_box(self) -> BoxCallableOnce<R, E>where
Self: Sized + 'static,
Converts this callable into a boxed callable.
§Returns
A BoxCallableOnce<R, E> that executes this callable when call() is
invoked.
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_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>where
Self: Sized + 'static,
fn into_runnable(self) -> BoxRunnableOnce<E>where
Self: Sized + 'static,
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.