Skip to main content

Callable

Trait Callable 

Source
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§

Source

fn call(self) -> Result<R, E>

Executes the computation, consuming self.

§Returns

Returns Ok(R) when the computation succeeds, or Err(E) when it fails. The exact error meaning is defined by the concrete callable.

Provided Methods§

Source

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.

Source

fn into_fn(self) -> impl FnOnce() -> Result<R, E>
where Self: Sized + 'static,

Converts this callable into a closure.

§Returns

A closure implementing FnOnce() -> Result<R, E>.

Source

fn to_box(&self) -> BoxCallable<R, E>
where Self: Clone + Sized + 'static,

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.

Source

fn to_fn(&self) -> impl FnOnce() -> Result<R, E>
where Self: Clone + Sized + 'static,

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>.

Source

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.

Implementors§

Source§

impl<F, R, E> Callable<R, E> for F
where F: FnOnce() -> Result<R, E>,

Source§

impl<R, E> Callable<R, E> for BoxCallable<R, E>