@@ -25,14 +25,17 @@ impl Foo {
2525These attributes do not work on typedefs, since typedefs are just aliases.
2626
2727Representations like ` #[repr(u8)] ` , ` #[repr(i64)] ` are for selecting the
28- discriminant size for enums with no data fields on any of the variants, e.g.
29- ` enum Color {Red, Blue, Green} ` , effectively setting the size of the enum to
30- the size of the provided type. Such an enum can be cast to a value of the same
31- type as well. In short, ` #[repr(u8)] ` makes the enum behave like an integer
32- with a constrained set of allowed values.
28+ discriminant size for enums. For enums with no data fields on any of the
29+ variants, e.g. ` enum Color {Red, Blue, Green} ` , this effectively sets the size
30+ of the enum to the size of the provided type. Such an enum can be cast to a
31+ value of the same type as well. In short, ` #[repr(u8)] ` makes a field-less enum
32+ behave like an integer with a constrained set of allowed values.
3333
34- Only field-less enums can be cast to numerical primitives, so this attribute
35- will not apply to structs.
34+ For a description of how ` #[repr(C)] ` and representations like ` #[repr(u8)] `
35+ affect the layout of enums with data fields, see [ RFC 2195] [ rfc2195 ] .
36+
37+ Only field-less enums can be cast to numerical primitives. Representations like
38+ ` #[repr(u8)] ` will not apply to structs.
3639
3740` #[repr(packed)] ` reduces padding to make the struct size smaller. The
3841representation of enums isn't strictly defined in Rust, and this attribute
@@ -42,3 +45,5 @@ won't work on enums.
4245types (i.e., ` u8 ` , ` i32 ` , etc) a representation that permits vectorization via
4346SIMD. This doesn't make much sense for enums since they don't consist of a
4447single list of data.
48+
49+ [ rfc2195 ] : https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md
0 commit comments