]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/language-features/repr-align-enum.md
Rollup merge of #61423 - davidtwco:correct-symbol-mangling, r=eddyb
[rust.git] / src / doc / unstable-book / src / language-features / repr-align-enum.md
1 # `repr_align_enum`
2
3 The tracking issue for this feature is: [#57996]
4
5 [#57996]: https://github.com/rust-lang/rust/issues/57996
6
7 ------------------------
8
9 The `repr_align_enum` feature allows using the `#[repr(align(x))]` attribute
10 on enums, similarly to structs.
11
12 # Examples
13
14 ```rust
15 #![feature(repr_align_enum)]
16
17 #[repr(align(8))]
18 enum Aligned {
19     Foo,
20     Bar { value: u32 },
21 }
22
23 fn main() {
24     assert_eq!(std::mem::align_of::<Aligned>(), 8);
25 }
26 ```
27
28 This is equivalent to using an aligned wrapper struct everywhere:
29
30 ```rust
31 #[repr(align(8))]
32 struct Aligned(Unaligned);
33
34 enum Unaligned {
35     Foo,
36     Bar { value: u32 },
37 }
38
39 fn main() {
40     assert_eq!(std::mem::align_of::<Aligned>(), 8);
41 }
42 ```