pub struct BoxCallableWith<T, R, E> { /* private fields */ }Expand description
Box-based callable with mutable input.
BoxCallableWith<T, R, E> stores a
Box<dyn FnMut(&mut T) -> Result<R, E>> and can be called repeatedly.
§Author
Haixing Hu
Implementations§
Source§impl<T, R, E> BoxCallableWith<T, R, E>
impl<T, R, E> BoxCallableWith<T, R, E>
Sourcepub fn new<F>(function: F) -> Self
pub fn new<F>(function: F) -> Self
Creates a new callable-with.
Wraps the provided closure in the appropriate smart pointer type for this callable-with implementation.
Examples found in repository?
examples/tasks/task_demo.rs (lines 58-61)
54fn demo_mutable_input_tasks() {
55 println!("--- Mutable-input tasks ---");
56
57 let mut state = 40;
58 let mut callable = BoxCallableWith::new(|input: &mut i32| {
59 *input += 2;
60 Ok::<i32, String>(*input)
61 });
62 println!("CallableWith result: {:?}", callable.call_with(&mut state));
63 println!("State after CallableWith: {state}");
64
65 let mut runnable = BoxRunnableWith::new(|input: &mut i32| {
66 *input *= 2;
67 Ok::<(), String>(())
68 });
69 println!("RunnableWith result: {:?}", runnable.run_with(&mut state));
70 println!("State after RunnableWith: {state}");
71 println!();
72}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-with.
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 with an optional name.
Wraps the provided closure and assigns it an optional name.
Sourcepub fn clear_name(&mut self)
pub fn clear_name(&mut self)
Clears the name of this callable-with.
Sourcepub fn map<U, M>(self, mapper: M) -> BoxCallableWith<T, U, E>where
M: FnMut(R) -> U + 'static,
T: 'static,
R: 'static,
E: 'static,
pub fn map<U, M>(self, mapper: M) -> BoxCallableWith<T, U, E>where
M: FnMut(R) -> U + 'static,
T: 'static,
R: 'static,
E: 'static,
Sourcepub fn map_err<E2, M>(self, mapper: M) -> BoxCallableWith<T, R, E2>where
M: FnMut(E) -> E2 + 'static,
T: 'static,
R: 'static,
E: 'static,
pub fn map_err<E2, M>(self, mapper: M) -> BoxCallableWith<T, R, E2>where
M: FnMut(E) -> E2 + 'static,
T: 'static,
R: 'static,
E: 'static,
Sourcepub fn and_then<U, N>(self, next: N) -> BoxCallableWith<T, U, E>
pub fn and_then<U, N>(self, next: N) -> BoxCallableWith<T, U, E>
Trait Implementations§
Source§impl<T, R, E> CallableWith<T, R, E> for BoxCallableWith<T, R, E>
impl<T, R, E> CallableWith<T, R, E> for BoxCallableWith<T, R, E>
Source§fn call_with(&mut self, input: &mut T) -> Result<R, E>
fn call_with(&mut self, input: &mut T) -> Result<R, E>
Executes the boxed callable with mutable input.
Source§fn into_runnable_with(self) -> BoxRunnableWith<T, E>where
Self: Sized + 'static,
fn into_runnable_with(self) -> BoxRunnableWith<T, E>where
Self: Sized + 'static,
Converts this boxed callable into a boxed runnable while preserving its name.
Source§fn into_box(self) -> BoxCallableWith<T, R, E>
fn into_box(self) -> BoxCallableWith<T, R, E>
Converts this callable into a boxed callable. Read more
Source§fn into_rc(self) -> RcCallableWith<T, R, E>where
Self: 'static,
fn into_rc(self) -> RcCallableWith<T, R, E>where
Self: 'static,
Converts this callable into an
Rc callable. Read moreSource§impl<T, R, E> Debug for BoxCallableWith<T, R, E>
impl<T, R, E> Debug for BoxCallableWith<T, R, E>
Auto Trait Implementations§
impl<T, R, E> Freeze for BoxCallableWith<T, R, E>
impl<T, R, E> !RefUnwindSafe for BoxCallableWith<T, R, E>
impl<T, R, E> !Send for BoxCallableWith<T, R, E>
impl<T, R, E> !Sync for BoxCallableWith<T, R, E>
impl<T, R, E> Unpin for BoxCallableWith<T, R, E>
impl<T, R, E> UnsafeUnpin for BoxCallableWith<T, R, E>
impl<T, R, E> !UnwindSafe for BoxCallableWith<T, 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