1#[macro_export]2macro_rules! dynamic_wrapper {3 ($orig: ident, $wrapper: ident) => {4 #[derive(Debug, Clone)]5 pub struct $wrapper(pub std::rc::Rc<dyn $orig>);6 impl std::ops::Deref for $wrapper {7 type Target = dyn $orig;8 fn deref(&self) -> &Self::Target {9 &*self.010 }11 }12 impl std::cmp::PartialEq for $wrapper {13 fn eq(&self, other: &Self) -> bool {14 Rc::ptr_eq(&self.0, &other.0)15 }16 }17 };18}1920#[macro_export]21macro_rules! future_wrapper {22 ($orig: ty, $wrapper: ident) => {23 #[derive(Debug, Clone)]24 pub struct $wrapper(pub std::rc::Rc<std::cell::RefCell<Option<$orig>>>);25 impl $wrapper {26 pub fn unwrap(self) -> $orig {27 self.0.borrow().as_ref().map(|e| e.clone()).unwrap()28 }29 pub fn new() -> Self {30 $wrapper(std::rc::Rc::new(std::cell::RefCell::new(None)))31 }32 pub fn fill(self, val: $orig) -> $orig {33 if self.0.borrow().is_some() {34 panic!("wrapper is filled already");35 }36 {37 self.0.borrow_mut().replace(val);38 }39 self.unwrap()40 }41 }42 };43}4445#[macro_export]46macro_rules! dummy_debug {47 ($struct: ident) => {48 impl std::fmt::Debug for $struct {49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {50 f.debug_struct(std::stringify!($struct))51 .finish_non_exhaustive()52 }53 }54 };55}