pub struct BoxRunnableOnce<E> { /* private fields */ }Expand description
Box-based one-time runnable.
BoxRunnableOnce<E> stores a
Box<dyn FnOnce() -> Result<(), E> + Send> and can be executed only once.
It is the boxed concrete implementation of RunnableOnce for task
objects that may be moved across threads.
§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(()));Implementations§
Source§impl<E> BoxRunnableOnce<E>
impl<E> BoxRunnableOnce<E>
Sourcepub fn new<F>(function: F) -> Self
pub fn new<F>(function: F) -> Self
Creates a new runnable.
Wraps the provided closure in the appropriate smart pointer type for this runnable implementation.
Examples found in repository?
75fn demo_once_tasks() {
76 println!("--- One-time tasks ---");
77
78 let callable_once = BoxCallableOnce::new(|| Ok::<String, String>(String::from("ready")));
79 println!("CallableOnce result: {:?}", callable_once.call());
80
81 let runnable_once = BoxRunnableOnce::new(|| {
82 println!("RunnableOnce side effect executed");
83 Ok::<(), String>(())
84 });
85 println!("RunnableOnce result: {:?}", runnable_once.run());
86 println!();
87}Sourcepub fn new_with_name<F>(name: &str, function: F) -> Self
pub fn new_with_name<F>(name: &str, function: F) -> Self
Creates a new named runnable.
Wraps the provided closure and assigns it a name, which is useful for debugging and logging purposes.
Sourcepub fn new_with_optional_name<F>(function: F, name: Option<String>) -> Self
pub fn new_with_optional_name<F>(function: F, name: Option<String>) -> Self
Creates a new named runnable with an optional name.
Wraps the provided closure and assigns it an optional name.
Sourcepub fn from_supplier<S>(supplier: S) -> Self
pub fn from_supplier<S>(supplier: S) -> Self
Sourcepub fn clear_name(&mut self)
pub fn clear_name(&mut self)
Clears the name of this runnable.
Sourcepub fn and_then<N>(self, next: N) -> BoxRunnableOnce<E>where
N: RunnableOnce<E> + Send + 'static,
E: 'static,
pub fn and_then<N>(self, next: N) -> BoxRunnableOnce<E>where
N: RunnableOnce<E> + Send + 'static,
E: 'static,
Sourcepub fn then_callable<R, C>(self, callable: C) -> BoxCallableOnce<R, E>where
C: CallableOnce<R, E> + Send + 'static,
R: 'static,
E: 'static,
pub fn then_callable<R, C>(self, callable: C) -> BoxCallableOnce<R, E>where
C: CallableOnce<R, E> + Send + 'static,
R: 'static,
E: 'static,
Trait Implementations§
Source§impl<E> Debug for BoxRunnableOnce<E>
impl<E> Debug for BoxRunnableOnce<E>
Source§impl<E> Display for BoxRunnableOnce<E>
impl<E> Display for BoxRunnableOnce<E>
Source§impl<E> RunnableOnce<E> for BoxRunnableOnce<E>
impl<E> RunnableOnce<E> for BoxRunnableOnce<E>
Source§fn into_callable(self) -> BoxCallableOnce<(), E>where
Self: Sized + 'static,
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_local_box(self) -> LocalBoxRunnableOnce<E>where
Self: Sized + 'static,
fn into_local_box(self) -> LocalBoxRunnableOnce<E>where
Self: Sized + 'static,
Converts this boxed runnable into a local boxed runnable while preserving its name.
Source§fn into_local_callable(self) -> LocalBoxCallableOnce<(), E>where
Self: Sized + 'static,
fn into_local_callable(self) -> LocalBoxCallableOnce<(), E>where
Self: Sized + 'static,
Converts this boxed runnable into a local boxed callable while preserving its name.