qubit_function/tasks/runnable_with/
rc_runnable_with.rs1#![allow(unused_imports)]
14
15use super::*;
16
17pub struct RcRunnableWith<T, E> {
23 pub(super) function: Rc<RefCell<dyn FnMut(&mut T) -> Result<(), E>>>,
25 pub(super) name: Option<String>,
27}
28
29impl<T, E> Clone for RcRunnableWith<T, E> {
30 #[inline]
31 fn clone(&self) -> Self {
32 Self {
33 function: Rc::clone(&self.function),
34 name: self.name.clone(),
35 }
36 }
37}
38
39impl<T, E> RcRunnableWith<T, E> {
40 impl_common_new_methods!(
41 (FnMut(&mut T) -> Result<(), E> + 'static),
42 |function| Rc::new(RefCell::new(function)),
43 "runnable-with"
44 );
45
46 impl_common_name_methods!("runnable-with");
47}
48
49impl<T, E> RunnableWith<T, E> for RcRunnableWith<T, E> {
50 #[inline]
52 fn run_with(&mut self, input: &mut T) -> Result<(), E> {
53 (self.function.borrow_mut())(input)
54 }
55
56 impl_rc_conversions!(
57 RcRunnableWith<T, E>,
58 BoxRunnableWith,
59 FnMut(input: &mut T) -> Result<(), E>
60 );
61}