Macro repr_offset::off

source ·
macro_rules! off {
    ($value:expr; $($fields:tt).+ ) => { ... };
    ( $($fields:tt).+ ) => { ... };
}
Expand description

Gets the FieldOffset for a (possibly nested) field, and an optionally passed in value.

The value argument is only necessary when the type that the fields are from can’t be inferred.

Example

use repr_offset::{
    for_examples::ReprC,
    off,
    FieldOffset, ROExtAcc,
};

let this = ReprC {a: 3u8, b: 5u8, c: 8u8, d: 13u8};

// The value must be passed to the macro when you want to call
// any method on the returned `FieldOffset`.
assert_eq!(off!(this; a).get(&this), &this.a);

assert_eq!(this.f_get(off!(this; b)), &this.b);

assert_eq!(this.f_get(off!(c)), &this.c);
assert_eq!(this.f_get(off!(d)), &this.d);