1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#[macro_export]
macro_rules! define_extern_type {
($target:ident) => ($crate::define_extern_type!($target => $target););
($target:ty => $defined_path:path) => {
unsafe impl ::static_reflect::StaticReflect for $target {
const TYPE_INFO: $crate::TypeInfo<'static> = $crate::TypeInfo::Extern {
name: stringify!($defined_path)
};
}
};
}
#[macro_export]
macro_rules! field_offset {
($target:path, $($field:ident),+) => {
unsafe {
let uninit = core::mem::MaybeUninit::<$target>::uninit();
let base = uninit.as_ptr();
(core::ptr::addr_of!((*base)$(.$field)*).cast::<u8>().offset_from(base as *const u8) as usize)
}
}
}