Skip to main content

RunnableOnce

Trait RunnableOnce 

Source
pub trait RunnableOnce<E> {
    // Required method
    fn run(self) -> Result<(), E>;

    // Provided methods
    fn into_box(self) -> BoxRunnableOnce<E>
       where Self: Sized + 'static { ... }
    fn into_fn(self) -> impl FnOnce() -> Result<(), E>
       where Self: Sized + 'static { ... }
    fn to_box(&self) -> BoxRunnableOnce<E>
       where Self: Clone + Sized + 'static { ... }
    fn to_fn(&self) -> impl FnOnce() -> Result<(), E>
       where Self: Clone + Sized + 'static { ... }
    fn into_callable(self) -> BoxCallableOnce<(), E>
       where Self: Sized + 'static { ... }
}
Expand description

A fallible one-time action.

Conceptually this matches FnOnce() -> Result<(), E>: run consumes self and returns Result<(), E>, but the surface uses task-oriented naming and helpers instead of closure types. It is a semantic specialization of SupplierOnce<Result<(), E>> for executable actions and deferred side effects.

Choose RunnableOnce when only success or failure matters; the success type is (). When callers need the success value R, use CallableOnce.

§Type Parameters

  • E - The error value returned when the action fails.

§Examples

use qubit_function::{RunnableOnce, BoxRunnableOnce};

let task = || Ok::<(), String>(());
assert_eq!(task.run(), Ok(()));

§Author

Haixing Hu

Required Methods§

Source

fn run(self) -> Result<(), E>

Executes the action, consuming self.

§Returns

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

Provided Methods§

Source

fn into_box(self) -> BoxRunnableOnce<E>
where Self: Sized + 'static,

Converts this runnable into a boxed runnable.

§Returns

A BoxRunnableOnce<E> that executes this runnable when run() is invoked.

Source

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

Converts this runnable into a closure.

§Returns

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

Source

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

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 BoxRunnableOnce<E> built from a clone of this runnable.

Source

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

Converts this runnable 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<(), E>.

Source

fn into_callable(self) -> BoxCallableOnce<(), E>
where Self: Sized + 'static,

Converts this runnable into a callable returning unit.

§Returns

A BoxCallableOnce<(), E> that executes this runnable and returns Ok(()) on success.

Implementors§

Source§

impl<E> RunnableOnce<E> for BoxRunnableOnce<E>

Source§

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