Skip to main content

BoxRunnable

Struct BoxRunnable 

Source
pub struct BoxRunnable<E> { /* private fields */ }
Expand description

Box-based one-time runnable.

BoxRunnable<E> stores a Box<dyn FnOnce() -> Result<(), E>> and can be executed only once. It is the boxed concrete implementation of Runnable.

§Type Parameters

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

§Examples

use qubit_function::{BoxRunnable, Runnable};

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

§Author

Haixing Hu

Implementations§

Source§

impl<E> BoxRunnable<E>

Source

pub fn new<F>(function: F) -> Self
where F: FnOnce() -> Result<(), E> + 'static,

Creates a new boxed runnable.

§Parameters
  • function - The one-time closure executed by this runnable.
§Returns

A new unnamed BoxRunnable<E>.

Source

pub fn new_with_name<F>(name: &str, function: F) -> Self
where F: FnOnce() -> Result<(), E> + 'static,

Creates a new named boxed runnable.

§Parameters
  • name - Name used by Debug and Display.
  • function - The one-time closure executed by this runnable.
§Returns

A new named BoxRunnable<E>.

Source

pub fn new_with_optional_name<F>(function: F, name: Option<String>) -> Self
where F: FnOnce() -> Result<(), E> + 'static,

Creates a new boxed runnable with an optional name.

§Parameters
  • function - The one-time closure executed by this runnable.
  • name - Optional name used by Debug and Display.
§Returns

A new BoxRunnable<E>.

Source

pub fn from_supplier<S>(supplier: S) -> Self
where S: SupplierOnce<Result<(), E>> + 'static,

Creates a boxed runnable from a one-time supplier.

This is an explicit bridge from SupplierOnce<Result<(), E>> to Runnable<E>.

§Parameters
  • supplier - The supplier that produces the runnable result.
§Returns

A new BoxRunnable<E>.

Source

pub fn name(&self) -> Option<&str>

Gets the optional runnable name.

§Returns

Returns Some(&str) if a name was set, or None otherwise.

Source

pub fn set_name(&mut self, name: &str)

Sets the runnable name.

§Parameters
  • name - The new name.
Source

pub fn clear_name(&mut self)

Clears the runnable name.

Source

pub fn and_then<N>(self, next: N) -> BoxRunnable<E>
where N: Runnable<E> + 'static, E: 'static,

Chains another runnable after this runnable succeeds.

The second runnable is not executed if this runnable returns Err.

§Parameters
  • next - The runnable to execute after this runnable succeeds.
§Returns

A new runnable executing both actions in sequence.

Source

pub fn then_callable<R, C>(self, callable: C) -> BoxCallable<R, E>
where C: Callable<R, E> + 'static, R: 'static, E: 'static,

Runs this runnable before a callable.

The callable is not executed if this runnable returns Err.

§Parameters
  • callable - The callable to execute after this runnable succeeds.
§Returns

A callable producing the second computation’s result.

Trait Implementations§

Source§

impl<E> Debug for BoxRunnable<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats this boxed runnable for debugging.

Source§

impl<E> Display for BoxRunnable<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats this boxed runnable for display.

Source§

impl<E> Runnable<E> for BoxRunnable<E>

Source§

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

Executes the boxed runnable.

Source§

fn into_box(self) -> BoxRunnable<E>

Returns this boxed runnable without re-boxing it.

Source§

fn into_fn(self) -> impl FnOnce() -> Result<(), E>

Extracts the underlying one-time closure.

Source§

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

Converts this boxed runnable into a boxed callable while preserving its name.

Source§

impl<E> SupplierOnce<Result<(), E>> for BoxRunnable<E>

Source§

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

Executes the boxed runnable as a one-time supplier of Result<(), E>.

Source§

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

Converts to BoxSupplierOnce. Read more
Source§

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

Converts the supplier to a Box<dyn FnOnce() -> T>. Read more

Auto Trait Implementations§

§

impl<E> Freeze for BoxRunnable<E>

§

impl<E> !RefUnwindSafe for BoxRunnable<E>

§

impl<E> !Send for BoxRunnable<E>

§

impl<E> !Sync for BoxRunnable<E>

§

impl<E> Unpin for BoxRunnable<E>

§

impl<E> UnsafeUnpin for BoxRunnable<E>

§

impl<E> !UnwindSafe for BoxRunnable<E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.