pub trait Callable<R, E> {
// Required method
fn call(self) -> Result<R, E>;
// Provided methods
fn into_box(self) -> BoxCallable<R, E>
where Self: Sized + 'static { ... }
fn into_fn(self) -> impl FnOnce() -> Result<R, E>
where Self: Sized + 'static { ... }
fn to_box(&self) -> BoxCallable<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) -> BoxRunnable<E>
where Self: Sized + 'static { ... }
}Expand description
A fallible one-time computation.
Callable<R, E> consumes itself and returns Result<R, E>. It is a
semantic specialization of SupplierOnce<Result<R, E>> for executable
computations and deferred tasks.
§Type Parameters
R- The success value returned by the computation.E- The error value returned when the computation fails.
§Examples
use qubit_function::Callable;
let task = || Ok::<i32, String>(21 * 2);
assert_eq!(task.call(), Ok(42));§Author
Haixing Hu
Required Methods§
Provided Methods§
Sourcefn into_box(self) -> BoxCallable<R, E>where
Self: Sized + 'static,
fn into_box(self) -> BoxCallable<R, E>where
Self: Sized + 'static,
Converts this callable into a boxed callable.
§Returns
A BoxCallable<R, E> that executes this callable when call() is
invoked.
Sourcefn to_box(&self) -> BoxCallable<R, E>
fn to_box(&self) -> BoxCallable<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 BoxCallable<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) -> BoxRunnable<E>where
Self: Sized + 'static,
fn into_runnable(self) -> BoxRunnable<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 BoxRunnable<E> that executes this callable and discards its success
value.