pub trait Callable<R, E> {
// Required method
fn call(&mut self) -> Result<R, E>;
// Provided methods
fn into_box(self) -> BoxCallable<R, E>
where Self: Sized + 'static { ... }
fn into_rc(self) -> RcCallable<R, E>
where Self: Sized + 'static { ... }
fn into_arc(self) -> ArcCallable<R, E>
where Self: Sized + Send + 'static { ... }
fn into_fn(self) -> impl FnMut() -> Result<R, E>
where Self: Sized + 'static { ... }
fn to_box(&self) -> BoxCallable<R, E>
where Self: Clone + Sized + 'static { ... }
fn to_rc(&self) -> RcCallable<R, E>
where Self: Clone + Sized + 'static { ... }
fn to_arc(&self) -> ArcCallable<R, E>
where Self: Clone + Send + Sized + 'static { ... }
fn to_fn(&self) -> impl FnMut() -> Result<R, E>
where Self: Clone + Sized + 'static { ... }
fn into_once(self) -> BoxCallableOnce<R, E>
where Self: Sized + 'static { ... }
fn to_once(&self) -> BoxCallableOnce<R, E>
where Self: Clone + Sized + 'static { ... }
fn into_runnable(self) -> BoxRunnable<E>
where Self: Sized + 'static { ... }
}Expand description
A fallible, reusable zero-argument computation.
Conceptually this is the same shape as FnMut() -> Result<R, E>: call takes
&mut self and returns Result<R, E>, but the API uses task-oriented naming
and helpers. In this crate it aligns with Supplier of Result<R, E>—a
fallible supplier—while emphasizing executable work rather than plain value
production.
Choose Callable when callers need the success value R. When only
success or failure matters, use Runnable, 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::Callable;
let mut task = || Ok::<i32, String>(21 * 2);
assert_eq!(task.call().expect("call should succeed"), 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 into_rc(self) -> RcCallable<R, E>where
Self: Sized + 'static,
fn into_rc(self) -> RcCallable<R, E>where
Self: Sized + 'static,
Sourcefn into_arc(self) -> ArcCallable<R, E>
fn into_arc(self) -> ArcCallable<R, E>
Sourcefn into_fn(self) -> impl FnMut() -> Result<R, E>where
Self: Sized + 'static,
fn into_fn(self) -> impl FnMut() -> Result<R, E>where
Self: Sized + 'static,
Converts this callable into a mutable closure.
§Returns
A closure implementing FnMut() -> Result<R, E>.
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_rc(&self) -> RcCallable<R, E>
fn to_rc(&self) -> RcCallable<R, E>
Converts this callable into an Rc callable without consuming self.
The method clones self and wraps the clone.
§Returns
A RcCallable<R, E>.
Sourcefn to_arc(&self) -> ArcCallable<R, E>
fn to_arc(&self) -> ArcCallable<R, E>
Converts this callable into an Arc callable without consuming self.
The method clones self and wraps the clone.
§Returns
An ArcCallable<R, E>.
Sourcefn to_fn(&self) -> impl FnMut() -> Result<R, E>
fn to_fn(&self) -> impl FnMut() -> Result<R, E>
Converts this callable into a mutable closure without consuming self.
The method clones self and returns a closure that executes the clone
on each call.
§Returns
A closure implementing FnMut() -> Result<R, E>.
Sourcefn into_once(self) -> BoxCallableOnce<R, E>where
Self: Sized + 'static,
fn into_once(self) -> BoxCallableOnce<R, E>where
Self: Sized + 'static,
Converts this callable into a one-time callable.
The returned callable consumes itself on each invocation.
§Returns
A BoxCallableOnce<R, E>.
Sourcefn to_once(&self) -> BoxCallableOnce<R, E>
fn to_once(&self) -> BoxCallableOnce<R, E>
Converts this callable into a one-time callable without consuming
self.
The method clones self and returns a one-time callable.
§Returns
A BoxCallableOnce<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.