pub struct BoxCallableOnce<R, E> { /* private fields */ }Expand description
Box-based one-time callable.
BoxCallableOnce<R, E> stores a
Box<dyn FnOnce() -> Result<R, E> + Send> and can be executed only once.
It is the boxed concrete implementation of CallableOnce for task
objects that may be moved across threads.
§Type Parameters
R- The success value returned by the computation.E- The error value returned when the computation fails.
§Examples
use qubit_function::{BoxCallableOnce, CallableOnce};
let task = BoxCallableOnce::new(|| Ok::<i32, String>(42));
assert_eq!(task.call(), Ok(42));Implementations§
Source§impl<R, E> BoxCallableOnce<R, E>
impl<R, E> BoxCallableOnce<R, E>
Sourcepub fn new<F>(function: F) -> Self
pub fn new<F>(function: F) -> Self
Creates a new callable.
Wraps the provided closure in the appropriate smart pointer type for this callable 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 callable.
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 callable 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 callable.
Sourcepub fn map<U, M>(self, mapper: M) -> BoxCallableOnce<U, E>
pub fn map<U, M>(self, mapper: M) -> BoxCallableOnce<U, E>
Sourcepub fn map_err<E2, M>(self, mapper: M) -> BoxCallableOnce<R, E2>
pub fn map_err<E2, M>(self, mapper: M) -> BoxCallableOnce<R, E2>
Sourcepub fn and_then<U, N>(self, next: N) -> BoxCallableOnce<U, E>
pub fn and_then<U, N>(self, next: N) -> BoxCallableOnce<U, E>
Trait Implementations§
Source§impl<R, E> CallableOnce<R, E> for BoxCallableOnce<R, E>
impl<R, E> CallableOnce<R, E> for BoxCallableOnce<R, E>
Source§fn into_runnable(self) -> BoxRunnableOnce<E>where
Self: Sized + 'static,
fn into_runnable(self) -> BoxRunnableOnce<E>where
Self: Sized + 'static,
Converts this boxed callable into a boxed runnable while preserving its name.
Source§fn into_local_box(self) -> LocalBoxCallableOnce<R, E>where
Self: Sized + 'static,
fn into_local_box(self) -> LocalBoxCallableOnce<R, E>where
Self: Sized + 'static,
Converts this boxed callable into a local boxed callable while preserving its name.
Source§fn into_local_runnable(self) -> LocalBoxRunnableOnce<E>where
Self: Sized + 'static,
fn into_local_runnable(self) -> LocalBoxRunnableOnce<E>where
Self: Sized + 'static,
Converts this boxed callable into a local boxed runnable while preserving its name.