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>> and can
be executed only once. It is the boxed concrete implementation of
CallableOnce.
§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));§Author
Haixing Hu
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.
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) -> Selfwhere
S: SupplierOnce<Result<R, E>> + 'static,
pub fn from_supplier<S>(supplier: S) -> Selfwhere
S: SupplierOnce<Result<R, E>> + 'static,
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>where
M: FnOnce(R) -> U + 'static,
R: 'static,
E: 'static,
pub fn map<U, M>(self, mapper: M) -> BoxCallableOnce<U, E>where
M: FnOnce(R) -> U + 'static,
R: 'static,
E: 'static,
Sourcepub fn map_err<E2, M>(self, mapper: M) -> BoxCallableOnce<R, E2>where
M: FnOnce(E) -> E2 + 'static,
R: 'static,
E: 'static,
pub fn map_err<E2, M>(self, mapper: M) -> BoxCallableOnce<R, E2>where
M: FnOnce(E) -> E2 + 'static,
R: 'static,
E: 'static,
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_box(self) -> BoxCallableOnce<R, E>
fn into_box(self) -> BoxCallableOnce<R, E>
Converts this callable into a boxed callable. Read more
Source§impl<R, E> Debug for BoxCallableOnce<R, E>
impl<R, E> Debug for BoxCallableOnce<R, E>
Source§impl<R, E> Display for BoxCallableOnce<R, E>
impl<R, E> Display for BoxCallableOnce<R, E>
Source§impl<R, E> SupplierOnce<Result<R, E>> for BoxCallableOnce<R, E>
impl<R, E> SupplierOnce<Result<R, E>> for BoxCallableOnce<R, E>
Auto Trait Implementations§
impl<R, E> Freeze for BoxCallableOnce<R, E>
impl<R, E> !RefUnwindSafe for BoxCallableOnce<R, E>
impl<R, E> !Send for BoxCallableOnce<R, E>
impl<R, E> !Sync for BoxCallableOnce<R, E>
impl<R, E> Unpin for BoxCallableOnce<R, E>
impl<R, E> UnsafeUnpin for BoxCallableOnce<R, E>
impl<R, E> !UnwindSafe for BoxCallableOnce<R, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more