Macro ostd::value_offset

source ยท
macro_rules! value_offset {
    ($container:ident) => { ... };
    ($container:ident.$($field:ident).*) => { ... };
}
Expand description

Gets the offset of a field within an object as a pointer.

#[repr(C)]
pub struct Foo {
    first: u8,
    second: u32,
}
let foo = &Foo {first: 0, second: 0};
assert!(value_offset!(foo) == (0 as *const Foo));
assert!(value_offset!(foo.first) == (0 as *const u8));
assert!(value_offset!(foo.second) == (4 as *const u32));