Type Alias repr_offset::get_field_offset::PrivFieldAlignment

source ·
pub type PrivFieldAlignment<This, FN> = <This as GetFieldOffset<FN>>::Alignment;
Expand description

Gets the alignment of a (potentially) private field in the GetFieldOffset<FN> impl for This.

§Warning

Because the field may be private this can break when asking for the alignment of fields in types from external crates.

§Example

use repr_offset::{
    for_examples::ReprPacked,
    get_field_offset::PrivFieldAlignment,
    tstr::TS,
    Aligned, Unaligned,
};

// Fields in ReprC are all aligned
let _: PrivFieldAlignment<Foo, TS!(x)> = Aligned;
let _: PrivFieldAlignment<Foo, TS!(y)> = Aligned;
let _: PrivFieldAlignment<Foo, TS!(z)> = Aligned;
let _: PrivFieldAlignment<Foo, TS!(w)> = Aligned;

// Fields in ReprPacked are all unaligned
let _: PrivFieldAlignment<Foo, TS!(y, a)> = Unaligned;
let _: PrivFieldAlignment<Foo, TS!(y, b)> = Unaligned;
let _: PrivFieldAlignment<Foo, TS!(y, c)> = Unaligned;
let _: PrivFieldAlignment<Foo, TS!(y, d)> = Unaligned;

mod foo {
    use super::*;
     
    type YField = ReprPacked<&'static str, &'static [u8], char, bool>;
    
    #[repr(C)]
    pub struct Foo {
        x: u8,
        pub(super) y: YField,
        pub(crate) z: u32,
        pub w: u64,
    }

    repr_offset::unsafe_struct_field_offsets!{
        alignment =  Aligned,
    
        impl[] Foo {
            const OFFSET_X, x: u8;
            pub(super) const OFFSET_Y, y: YField;
            pub(crate) const OFFSET_Z, z: u32;
            pub const OFFSET_W, w: u64;
        }
    }
}

use foo::Foo;