Module repr_offset::ext

source ·
Expand description

Extension traits that use FieldOffset parameters to operate on fields.

These are the extension traits for each kind of type:

§Imports

Here is the code to import all of the extension traits for convenience:

use repr_offset::{ROExtAcc, ROExtOps, ROExtRawAcc, ROExtRawMutAcc, ROExtRawOps, ROExtRawMutOps};

§Examples

§Initializing Types

use repr_offset::{
    for_examples::ReprC,
    off,
    ROExtRawMutOps,
};

use std::mem::MaybeUninit;

type This = ReprC<String, Vec<u8>, usize, Option<char>>;

let this = unsafe{
    let mut uninit = MaybeUninit::<This>::uninit();
    initialize_this(uninit.as_mut_ptr());
    uninit.assume_init()
};

assert_eq!(this.a, "foo");
assert_eq!(this.b, [3, 5, 8]);
assert_eq!(this.c, 13);
assert_eq!(this.d, Some('_'));

/// Initializes `this`
///
/// # Safety
///
/// The passed in pointer must point to an aligned, allocated `This` (including on the stack).
unsafe fn initialize_this(this: *mut This) {
    this.f_write(off!(a), "foo".to_string());
    this.f_write(off!(b), vec![3, 5, 8]);
    this.f_write(off!(c), 13_usize);
    this.f_write(off!(d), Some('_'));
}

Traits§

  • Extension trait for (mutable) references to access fields generically, where the field is determined by a FieldOffset parameter.
  • Extension trait for (mutable) references to do generic field operations, where the field is determined by a FieldOffset parameter.
  • Extension trait for raw pointers to access fields generically, where the field is determined by a FieldOffset parameter.
  • Extension trait for mutable raw pointers to access fields generically, where the field is determined by a FieldOffset parameter.
  • Extension trait for mutable raw pointers to do generic field operations, where the field is determined by a FieldOffset parameter.
  • Extension trait for raw pointers to do generic field operations, where the field is determined by a FieldOffset parameter.