Skip to main content

BoxRunnable

Struct BoxRunnable 

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

Box-based reusable runnable.

BoxRunnable<E> stores a Box<dyn FnMut() -> Result<(), E>> and can be executed repeatedly. 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 mut 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: FnMut() -> 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: FnMut() -> 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: FnMut() -> 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: Supplier<Result<(), E>> + 'static,

Creates a boxed runnable from a reusable supplier.

This is an explicit bridge from Supplier<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 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) -> 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 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 the value using the given formatter. Read more
Source§

impl<E> Display for BoxRunnable<E>

Source§

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

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

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

Source§

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

Executes the boxed runnable.

Source§

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

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

Source§

fn into_box(self) -> BoxRunnable<E>

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

fn into_rc(self) -> RcRunnable<E>
where Self: 'static,

Converts this runnable into a shared single-threaded runnable. Read more
Source§

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

Converts this runnable into a mutable closure. Read more
Source§

fn into_arc(self) -> ArcRunnable<E>
where Self: Sized + Send + 'static,

Converts this runnable into a shared thread-safe runnable. Read more
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.