pub struct BoxCallable<R, E> { /* private fields */ }Expand description
Box-based callable.
BoxCallable<R, E> stores a Box<dyn FnMut() -> Result<R, E>> and can be
called repeatedly. It is the boxed concrete implementation of
Callable.
§Type Parameters
R- The success value returned by the computation.E- The error value returned when the computation fails.
§Example
use qubit_function::{BoxCallable, Callable};
let mut task = BoxCallable::new(|| Ok::<i32, String>(42));
assert_eq!(task.call().expect("call should succeed"), 42);§Author
Haixing Hu
Implementations§
Source§impl<R, E> BoxCallable<R, E>
impl<R, E> BoxCallable<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) -> 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) -> BoxCallable<U, E>where
M: FnMut(R) -> U + 'static,
R: 'static,
E: 'static,
pub fn map<U, M>(self, mapper: M) -> BoxCallable<U, E>where
M: FnMut(R) -> U + 'static,
R: 'static,
E: 'static,
Sourcepub fn map_err<E2, M>(self, mapper: M) -> BoxCallable<R, E2>where
M: FnMut(E) -> E2 + 'static,
R: 'static,
E: 'static,
pub fn map_err<E2, M>(self, mapper: M) -> BoxCallable<R, E2>where
M: FnMut(E) -> E2 + 'static,
R: 'static,
E: 'static,
Sourcepub fn and_then<U, N>(self, next: N) -> BoxCallable<U, E>
pub fn and_then<U, N>(self, next: N) -> BoxCallable<U, E>
Trait Implementations§
Source§impl<R, E> Callable<R, E> for BoxCallable<R, E>
impl<R, E> Callable<R, E> for BoxCallable<R, E>
Source§fn into_runnable(self) -> BoxRunnable<E>where
Self: Sized + 'static,
fn into_runnable(self) -> BoxRunnable<E>where
Self: Sized + 'static,
Converts this boxed callable into a boxed runnable while preserving its name.
Source§fn into_box(self) -> BoxCallable<R, E>
fn into_box(self) -> BoxCallable<R, E>
Converts this callable into a boxed callable. Read more
Source§fn into_rc(self) -> RcCallable<R, E>where
Self: 'static,
fn into_rc(self) -> RcCallable<R, E>where
Self: 'static,
Converts this callable into an
Rc callable. Read moreSource§fn into_fn(self) -> impl FnMut() -> Result<R, E>
fn into_fn(self) -> impl FnMut() -> Result<R, E>
Converts this callable into a mutable closure. Read more
Source§fn into_once(self) -> BoxCallableOnce<R, E>where
Self: 'static,
fn into_once(self) -> BoxCallableOnce<R, E>where
Self: 'static,
Converts this callable into a one-time callable. Read more
Source§impl<R, E> Debug for BoxCallable<R, E>
impl<R, E> Debug for BoxCallable<R, E>
Auto Trait Implementations§
impl<R, E> Freeze for BoxCallable<R, E>
impl<R, E> !RefUnwindSafe for BoxCallable<R, E>
impl<R, E> !Send for BoxCallable<R, E>
impl<R, E> !Sync for BoxCallable<R, E>
impl<R, E> Unpin for BoxCallable<R, E>
impl<R, E> UnsafeUnpin for BoxCallable<R, E>
impl<R, E> !UnwindSafe for BoxCallable<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