Skip to main content

define_shared_wrapper

Macro define_shared_wrapper 

Source
macro_rules! define_shared_wrapper {
    ($name:ident<$ty:ty>) => { ... };
}
Expand description

Define a wrapper struct that holds an Rc containing the given type. It implements Clone to copy the Rc and implements Deref to access the value inside the Rc.

For example: define_shared_wrapper!(Example<usize>) would expand to:

#[derive(Clone)]
#[doc(hidden)]
pub struct Example(pub std::rc::Rc<usize>);

impl std::ops::Deref for Example {
     type Target = usize;

     fn deref(&self) -> &Self::Target {
        self.0.deref()
     }
}