Struct repr_offset::offset_calc::GetNextFieldOffset
source · pub struct GetNextFieldOffset {
pub previous_offset: usize,
pub previous_size: usize,
pub container_alignment: usize,
pub next_alignment: usize,
}
Expand description
Calculates the offset (in bytes) of a field, with the call
method.
§Example
use repr_offset::offset_calc::GetNextFieldOffset;
use std::mem;
#[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 = GetNextFieldOffset{
previous_offset: OFFSET_0,
previous_size: mem::size_of::<u8>(),
container_alignment: mem::align_of::<Foo>(),
next_alignment: mem::align_of::<u16>(),
}.call();
const OFFSET_2: usize = GetNextFieldOffset{
previous_offset: OFFSET_1,
previous_size: mem::size_of::<u16>(),
container_alignment: mem::align_of::<Foo>(),
next_alignment: mem::align_of::<u32>(),
}.call();
const OFFSET_3: usize = GetNextFieldOffset{
previous_offset: OFFSET_2,
previous_size: mem::size_of::<u32>(),
container_alignment: mem::align_of::<Foo>(),
next_alignment: mem::align_of::<u64>(),
}.call();
Fields§
§previous_offset: usize
The offset in bytes of the previous field.
previous_size: usize
The size of the previous field.
container_alignment: usize
The alignment of the type that contains the field.
next_alignment: usize
The alignment of the field that this calculates the offset for.
Implementations§
Auto Trait Implementations§
impl Freeze for GetNextFieldOffset
impl RefUnwindSafe for GetNextFieldOffset
impl Send for GetNextFieldOffset
impl Sync for GetNextFieldOffset
impl Unpin for GetNextFieldOffset
impl UnwindSafe for GetNextFieldOffset
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
Gets a reference to a field, determined by
offset
. Read moresource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
Gets a muatble reference to a field, determined by
offset
. Read moresource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
Gets a const pointer to a field,
the field is determined by
offset
. Read moresource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
Gets a mutable pointer to a field, determined by
offset
. Read moresource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
Replaces a field (determined by
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
Replaces a field (determined by
offset
) with value
,
returning the previous value of the field. Read more