Skip to content

Commit 63b9a03

Browse files
committed
Add an define_extern_type! macro
Replacement for DuckASM's old define_opaque_type!
1 parent 26e1204 commit 63b9a03

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/macros.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/// Define a type's implementation of [StaticReflect](crate::StaticReflect) as an extern type
2+
///
3+
/// See [TypeInfo::Extern](crate::types::TypeInfo::Extern)
4+
#[macro_export]
5+
macro_rules! define_extern_type {
6+
($target:ident) => (define_extern_type!($target => $target););
7+
($target:ty => $defined_path:path) => {
8+
impl ::static_reflect::StaticReflect for $target {
9+
const TYPE_INFO: $crate::TypeInfo<'static> = $crate::TypeInfo::Extern {
10+
name: stringify!($defined_path)
11+
};
12+
}
13+
};
14+
}
115

216
/// Get the integer offset of the specified field
317
#[macro_export]
@@ -12,4 +26,4 @@ macro_rules! field_offset {
1226
(std::ptr::addr_of!((*(1 as *mut $target))$(.$field)*) as usize) - 1
1327
}
1428
}
15-
}
29+
}

0 commit comments

Comments
 (0)