pub trait Runnable<E> {
// Required method
fn run(&mut self) -> Result<(), E>;
// Provided methods
fn into_box(self) -> BoxRunnable<E>
where Self: Sized + 'static { ... }
fn into_rc(self) -> RcRunnable<E>
where Self: Sized + 'static { ... }
fn into_arc(self) -> ArcRunnable<E>
where Self: Sized + Send + 'static { ... }
fn into_fn(self) -> impl FnMut() -> Result<(), E>
where Self: Sized + 'static { ... }
fn to_box(&self) -> BoxRunnable<E>
where Self: Clone + Sized + 'static { ... }
fn to_fn(&self) -> impl FnMut() -> Result<(), E>
where Self: Clone + Sized + 'static { ... }
fn to_rc(&self) -> RcRunnable<E>
where Self: Clone + Sized + 'static { ... }
fn to_arc(&self) -> ArcRunnable<E>
where Self: Clone + Send + Sized + 'static { ... }
fn into_callable(self) -> BoxCallable<(), E>
where Self: Sized + 'static { ... }
}Expand description
A fallible, reusable, zero-argument action.
Conceptually, Runnable<E> matches FnMut () -> Result<(), E>, but
uses task-oriented vocabulary. Prefer it when the operation’s side effect
matters and only success or failure need to be reported.
Each call borrows self mutably and returns Result::Ok with unit or
Result::Err with E. Semantically, this is a specialization of
SupplierOnce<Result<(), E>> for executable actions and deferred side
effects.
The trait does not require Send. Concurrent executors should require
Runnable<E> + Send + 'static (or similar) at their API boundary.
§Type Parameters
E- The error value returned when the action fails.
§Examples
use qubit_function::Runnable;
let mut task = || Ok::<(), String>(());
assert_eq!(task.run(), Ok(()));§Author
Haixing Hu
Required Methods§
Provided Methods§
Sourcefn into_box(self) -> BoxRunnable<E>where
Self: Sized + 'static,
fn into_box(self) -> BoxRunnable<E>where
Self: Sized + 'static,
Converts this runnable into a boxed runnable.
§Returns
A BoxRunnable<E> that executes this runnable when run() is invoked.
Sourcefn into_rc(self) -> RcRunnable<E>where
Self: Sized + 'static,
fn into_rc(self) -> RcRunnable<E>where
Self: Sized + 'static,
Converts this runnable into a shared single-threaded runnable.
§Returns
An RcRunnable<E> that executes this runnable when run() is invoked.
Sourcefn into_arc(self) -> ArcRunnable<E>
fn into_arc(self) -> ArcRunnable<E>
Converts this runnable into a shared thread-safe runnable.
§Returns
An ArcRunnable<E> that executes this runnable when run() is invoked.
Sourcefn into_fn(self) -> impl FnMut() -> Result<(), E>where
Self: Sized + 'static,
fn into_fn(self) -> impl FnMut() -> Result<(), E>where
Self: Sized + 'static,
Converts this runnable into a mutable closure.
§Returns
A closure implementing FnMut() -> Result<(), E>.
Sourcefn to_box(&self) -> BoxRunnable<E>
fn to_box(&self) -> BoxRunnable<E>
Converts this runnable into a boxed runnable without consuming self.
The method clones self and boxes the clone. Use this for cloneable
runnable values that need to be reused after boxing.
§Returns
A new BoxRunnable<E> built from a clone of this runnable.
Sourcefn to_fn(&self) -> impl FnMut() -> Result<(), E>
fn to_fn(&self) -> impl FnMut() -> Result<(), E>
Converts this runnable into a mutable closure without consuming self.
The method clones self and returns a mutable closure that executes
the clone.
§Returns
A closure implementing FnMut() -> Result<(), E>.
Sourcefn to_rc(&self) -> RcRunnable<E>
fn to_rc(&self) -> RcRunnable<E>
Converts this runnable into a shared single-threaded runnable without
consuming self.
The method clones self and wraps the clone.
§Returns
A new RcRunnable<E> built from a clone of this runnable.
Sourcefn to_arc(&self) -> ArcRunnable<E>
fn to_arc(&self) -> ArcRunnable<E>
Converts this runnable into a shared thread-safe runnable without
consuming self.
The method clones self and wraps the clone.
§Returns
A new ArcRunnable<E> built from a clone of this runnable.
Sourcefn into_callable(self) -> BoxCallable<(), E>where
Self: Sized + 'static,
fn into_callable(self) -> BoxCallable<(), E>where
Self: Sized + 'static,
Converts this runnable into a callable returning unit.
§Returns
A BoxCallable<(), E> that executes this runnable and returns
Ok(()) on success.