pub struct BoxRunnableWith<T, E> { /* private fields */ }Expand description
Box-based runnable with mutable input.
BoxRunnableWith<T, E> stores a
Box<dyn FnMut(&mut T) -> Result<(), E>> and can be called repeatedly.
§Author
Haixing Hu
Implementations§
Source§impl<T, E> BoxRunnableWith<T, E>
impl<T, E> BoxRunnableWith<T, E>
Sourcepub fn new<F>(function: F) -> Self
pub fn new<F>(function: F) -> Self
Creates a new runnable-with.
Wraps the provided closure in the appropriate smart pointer type for this runnable-with implementation.
Examples found in repository?
examples/tasks/task_demo.rs (lines 65-68)
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 runnable-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 runnable-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 runnable-with.
Sourcepub fn and_then<N>(self, next: N) -> BoxRunnableWith<T, E>where
N: RunnableWith<T, E> + 'static,
T: 'static,
E: 'static,
pub fn and_then<N>(self, next: N) -> BoxRunnableWith<T, E>where
N: RunnableWith<T, E> + 'static,
T: 'static,
E: 'static,
Sourcepub fn then_callable_with<R, C>(self, callable: C) -> BoxCallableWith<T, R, E>where
C: CallableWith<T, R, E> + 'static,
T: 'static,
R: 'static,
E: 'static,
pub fn then_callable_with<R, C>(self, callable: C) -> BoxCallableWith<T, R, E>where
C: CallableWith<T, R, E> + 'static,
T: 'static,
R: 'static,
E: 'static,
Trait Implementations§
Source§impl<T, E> Debug for BoxRunnableWith<T, E>
impl<T, E> Debug for BoxRunnableWith<T, E>
Source§impl<T, E> Display for BoxRunnableWith<T, E>
impl<T, E> Display for BoxRunnableWith<T, E>
Source§impl<T, E> RunnableWith<T, E> for BoxRunnableWith<T, E>
impl<T, E> RunnableWith<T, E> for BoxRunnableWith<T, E>
Source§fn run_with(&mut self, input: &mut T) -> Result<(), E>
fn run_with(&mut self, input: &mut T) -> Result<(), E>
Executes the boxed runnable with mutable input.
Source§fn into_callable_with(self) -> BoxCallableWith<T, (), E>where
Self: Sized + 'static,
fn into_callable_with(self) -> BoxCallableWith<T, (), E>where
Self: Sized + 'static,
Converts this boxed runnable into a boxed callable while preserving its name.
Source§fn into_box(self) -> BoxRunnableWith<T, E>
fn into_box(self) -> BoxRunnableWith<T, E>
Converts this runnable into a boxed runnable. Read more
Source§fn into_rc(self) -> RcRunnableWith<T, E>where
Self: 'static,
fn into_rc(self) -> RcRunnableWith<T, E>where
Self: 'static,
Converts this runnable into an
Rc runnable. Read moreAuto Trait Implementations§
impl<T, E> Freeze for BoxRunnableWith<T, E>
impl<T, E> !RefUnwindSafe for BoxRunnableWith<T, E>
impl<T, E> !Send for BoxRunnableWith<T, E>
impl<T, E> !Sync for BoxRunnableWith<T, E>
impl<T, E> Unpin for BoxRunnableWith<T, E>
impl<T, E> UnsafeUnpin for BoxRunnableWith<T, E>
impl<T, E> !UnwindSafe for BoxRunnableWith<T, 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