Split up src/obj.rs
* common macros are in their own private module * functions are in their own obj::function module Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
43
src/obj/macros.rs
Normal file
43
src/obj/macros.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
macro_rules! impl_base_obj {
|
||||
($base_name:ident) => {
|
||||
fn instantiate(&mut self, ty: $crate::obj::ObjP) {
|
||||
self.$base_name.instantiate(ty);
|
||||
}
|
||||
|
||||
fn is_instantiated(&self) -> bool {
|
||||
self.$base_name.is_instantiated()
|
||||
}
|
||||
|
||||
fn attrs(&self) -> &$crate::obj::Attrs {
|
||||
self.$base_name.attrs()
|
||||
}
|
||||
|
||||
fn attrs_mut(&mut self) -> &mut $crate::obj::Attrs {
|
||||
self.$base_name.attrs_mut()
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
};
|
||||
() => {
|
||||
impl_base_obj! { base }
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_create {
|
||||
($($arg:ident : $ty:ty),* $(,)?) => {
|
||||
pub fn create(ty: $crate::obj::ObjP $(, $arg : $ty )*) -> $crate::obj::ObjP {
|
||||
let ptr = make_ptr(Self::new($($arg),*));
|
||||
ptr.borrow_mut().instantiate(ty);
|
||||
ptr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) use impl_base_obj;
|
||||
pub(crate) use impl_create;
|
||||
Reference in New Issue
Block a user