Skip to main content

BoxRunnableOnce

Struct BoxRunnableOnce 

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

Box-based one-time runnable.

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

§Type Parameters

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

§Examples

use qubit_function::{BoxRunnableOnce, RunnableOnce};

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

§Author

Haixing Hu

Implementations§

Source§

impl<E> BoxRunnableOnce<E>

Source

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

Creates a new runnable.

Wraps the provided closure in the appropriate smart pointer type for this runnable implementation.

Source

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

Creates a new named runnable.

Wraps the provided closure and assigns it a name, which is useful for debugging and logging purposes.

Source

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

Creates a new named runnable with an optional name.

Wraps the provided closure and assigns it an optional name.

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

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

A new BoxRunnableOnce<E>.

Source

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

Gets the name of this runnable.

§Returns

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

Source

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

Sets the name of this runnable.

§Parameters
  • name - The name to set for this runnable
Source

pub fn clear_name(&mut self)

Clears the name of this runnable.

Source

pub fn and_then<N>(self, next: N) -> BoxRunnableOnce<E>
where N: RunnableOnce<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) -> BoxCallableOnce<R, E>
where C: CallableOnce<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 BoxRunnableOnce<E>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<E> Display for BoxRunnableOnce<E>

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

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

Executes the boxed runnable.

Source§

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

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

Source§

fn into_box(self) -> BoxRunnableOnce<E>

Converts this runnable into a boxed runnable. Read more
Source§

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

Converts this runnable into a closure. Read more
Source§

impl<E> SupplierOnce<Result<(), E>> for BoxRunnableOnce<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 BoxRunnableOnce<E>

§

impl<E> !RefUnwindSafe for BoxRunnableOnce<E>

§

impl<E> !Send for BoxRunnableOnce<E>

§

impl<E> !Sync for BoxRunnableOnce<E>

§

impl<E> Unpin for BoxRunnableOnce<E>

§

impl<E> UnsafeUnpin for BoxRunnableOnce<E>

§

impl<E> !UnwindSafe for BoxRunnableOnce<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.