@@ -58,20 +58,18 @@ a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 };
5858In this example, ` Cat ` is a _ struct-like enum variant_ , whereas ` Dog ` is simply
5959called an enum variant.
6060
61+ An enum where no constructors contain fields are called a
62+ * <a name =" field-less-enum " >field-less enum</a >* .
63+
6164## Discriminants
6265
6366Each enum instance has a _ discriminant_ : an integer logically associated to it
64- that is used to determine which variant it holds. An opaque reference to this
65- discriminant can be obtained with the [ ` mem::discriminant ` ] function.
67+ that is used to determine which variant it holds.
6668
6769Under the [ default representation] , the discriminant is interpreted as
6870an ` isize ` value. However, the compiler is allowed to use a smaller type (or
6971another means of distinguishing variants) in its actual memory layout.
7072
71- If the [ primitive representation] or the [ ` C ` representation] is used, the
72- leading bytes of a variant (for example, two bytes if ` #[repr(u16)] ` is used), will
73- correspond exactly to the discriminant.
74-
7573### Assigning Discriminant Values
7674
7775#### Explicit Discriminants
@@ -85,7 +83,6 @@ following the variant name with `=` and a [constant expression]:
8583if the enumeration is "C-like" (i.e., it has no tuple or struct variants); e.g.:
8684
8785``` rust
88- # #![feature(arbitrary_enum_discriminant)]
8986enum Enum {
9087 Foo = 3 ,
9188 Bar = 2 ,
@@ -98,7 +95,6 @@ enum Enum {
9895if a [ primitive representation] is used. For example:
9996
10097``` rust
101- # #![feature(arbitrary_enum_discriminant)]
10298#[repr(u8 )]
10399enum Enum {
104100 Unit = 3 ,
@@ -165,12 +161,18 @@ enum OverflowingDiscriminantError2 {
165161}
166162```
167163
168- ### Accessing Discriminant Values
164+ ### Accessing Discriminant
165+
166+ #### Via ` mem::discriminant `
167+
168+ [ ` mem::discriminant ` ] returns an opaque reference to the discriminant of
169+ an enum value which can be compared. This cannot be used to get the value
170+ of the discriminant.
169171
170172#### Casting
171173
172- If there is no data attached to * any * of the variants of an enumeration, then
173- the discriminant can be directly accessed with a [ numeric cast] ; e.g.:
174+ If an enumeration is fieldless, then its discriminant can be directly
175+ accessed with a [ numeric cast] ; e.g.:
174176
175177``` rust
176178enum Enum {
0 commit comments