Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 699 Bytes

repr-align-enum.md

File metadata and controls

42 lines (30 loc) · 699 Bytes

repr_align_enum

The tracking issue for this feature is: #57996


The repr_align_enum feature allows using the #[repr(align(x))] attribute on enums, similarly to structs.

Examples

#![feature(repr_align_enum)]

#[repr(align(8))]
enum Aligned {
    Foo,
    Bar { value: u32 },
}

fn main() {
    assert_eq!(std::mem::align_of::<Aligned>(), 8);
}

This is equivalent to using an aligned wrapper struct everywhere:

#[repr(align(8))]
struct Aligned(Unaligned);

enum Unaligned {
    Foo,
    Bar { value: u32 },
}

fn main() {
    assert_eq!(std::mem::align_of::<Aligned>(), 8);
}