#![allow(unused_imports)]
use super::*;
pub struct RcRunnable<E> {
pub(super) function: Rc<RefCell<dyn FnMut() -> Result<(), E>>>,
pub(super) name: Option<String>,
}
impl<E> Clone for RcRunnable<E> {
#[inline]
fn clone(&self) -> Self {
Self {
function: Rc::clone(&self.function),
name: self.name.clone(),
}
}
}
impl<E> RcRunnable<E> {
impl_common_new_methods!(
(FnMut() -> Result<(), E> + 'static),
|function| Rc::new(RefCell::new(function)),
"runnable"
);
#[inline]
pub fn from_supplier<S>(supplier: S) -> Self
where
S: Supplier<Result<(), E>> + 'static,
{
Self::new(move || supplier.get())
}
impl_common_name_methods!("runnable");
}
impl<E> Runnable<E> for RcRunnable<E> {
#[inline]
fn run(&mut self) -> Result<(), E> {
(self.function.borrow_mut())()
}
impl_rc_conversions!(
RcRunnable<E>,
BoxRunnable,
FnMut() -> Result<(), E>
);
}