memoffset

Macro offset_of_union

Source
macro_rules! offset_of_union {
    ($parent:path, $field:tt) => { ... };
}
Expand description

Calculates the offset of the specified union member from the start of the union.

§Examples

use memoffset::offset_of_union;

#[repr(C, packed)]
union Foo {
    foo32: i32,
    foo64: i64,
}

fn main() {
    assert!(offset_of_union!(Foo, foo64) == 0);
}

§Note

Due to macro_rules limitations, this macro will accept structs with a single field as well as unions. This is not a stable guarantee, and future versions of this crate might fail on any use of this macro with a struct, without a semver bump.