macro_rules! offset_of { ($container:ty, $($field:tt)+) => { ... }; }
Expand description
Gets the offset of a field within a type as a pointer.
#[repr(C)]
pub struct Foo {
first: u8,
second: u32,
}
assert!(offset_of(Foo, first) == (0 as *const u8));
assert!(offset_of(Foo, second) == (4 as *const u32));