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§

source§

impl GetNextFieldOffset

source

pub const fn call(self) -> usize

Calculates the offset (in bytes) of a field.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<S> ROExtAcc for S

source§

fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F

Gets a reference to a field, determined by offset. Read more
source§

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 more
source§

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 more
source§

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 more
source§

impl<S> ROExtOps<Aligned> for S

source§

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 more
source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
source§

impl<S> ROExtOps<Unaligned> for S

source§

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
source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.