qubit_function/tasks/runnable_with/
arc_runnable_with.rs1#![allow(unused_imports)]
12
13use super::*;
14
15pub struct ArcRunnableWith<T, E> {
24 pub(super) function: Arc<Mutex<dyn FnMut(&mut T) -> Result<(), E> + Send>>,
26 pub(super) name: Option<String>,
28}
29
30impl<T, E> Clone for ArcRunnableWith<T, E> {
31 #[inline]
32 fn clone(&self) -> Self {
33 Self {
34 function: Arc::clone(&self.function),
35 name: self.name.clone(),
36 }
37 }
38}
39
40impl<T, E> ArcRunnableWith<T, E> {
41 impl_common_new_methods!(
42 (FnMut(&mut T) -> Result<(), E> + Send + 'static),
43 |function| Arc::new(Mutex::new(function)),
44 "runnable-with"
45 );
46
47 impl_common_name_methods!("runnable-with");
48}
49
50impl<T, E> RunnableWith<T, E> for ArcRunnableWith<T, E> {
51 #[inline]
53 fn run_with(&mut self, input: &mut T) -> Result<(), E> {
54 (self.function.lock())(input)
55 }
56
57 impl_arc_conversions!(
58 ArcRunnableWith<T, E>,
59 BoxRunnableWith,
60 RcRunnableWith,
61 FnMut(input: &mut T) -> Result<(), E>
62 );
63}
64
65impl_closure_trait!(
66 RunnableWith<T, E>,
67 run_with,
68 FnMut(input: &mut T) -> Result<(), E>
69);
70
71impl_function_debug_display!(BoxRunnableWith<T, E>);
72impl_function_debug_display!(RcRunnableWith<T, E>);
73impl_function_debug_display!(ArcRunnableWith<T, E>);