Function repr_offset::offset_calc::next_field_offset
source · pub const fn next_field_offset<Struct, Prev, Next>(
previous_offset: usize,
) -> usize
Expand description
Calculates the offset of a field in bytes,given the previous field.
§Parameters
Struct
is the struct that contains the field that this calculates the offset for.
Prev
is the type of the previous field.
Next
is the type of the field that this calculates the offset for.
previous_offset
is the offset in bytes of the previous field,of Prev
type.
§Example
use repr_offset::offset_calc::next_field_offset;
#[repr(C, packed)]
struct Foo(u8, u16, u32, u64);
assert_eq!( OFFSET_1, 1 );
assert_eq!( OFFSET_2, 3 );
assert_eq!( OFFSET_3, 7 );
const OFFSET_0: usize = 0;
const OFFSET_1: usize = next_field_offset::<Foo, u8, u16>(OFFSET_0);
const OFFSET_2: usize = next_field_offset::<Foo, u16, u32>(OFFSET_1);
const OFFSET_3: usize = next_field_offset::<Foo, u32, u64>(OFFSET_2);