macro_rules! offset_of {
    ($t: path => $f: tt) => { ... };
    ($t: path => $f: ident: $($rest: tt)*) => { ... };
}
Expand description

This macro allows safe construction of a FieldOffset, by generating a known to be valid lambda to pass to the constructor. It takes a type, and the identifier of a field within that type as input.

Examples:

Offset of field Foo.bar

#[repr(C)]
struct Foo { foo: i32, bar: i32 }
assert_eq!(offset_of!(Foo => bar).get_byte_offset(), 4);

Offset of nested field Foo.bar.x

struct Bar { a: u8, x: u8 }
struct Foo { foo: i32, bar: Bar }
assert_eq!(offset_of!(Foo => bar: Bar => x).get_byte_offset(), 5);