diff --git a/src/doc/reference.md b/src/doc/reference.md index c8e31f27b35..a27d6c6e268 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1413,6 +1413,27 @@ a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 }; In this example, `Cat` is a _struct-like enum variant_, whereas `Dog` is simply called an enum variant. +Enums have a discriminant. You can assign them explicitly: + +``` +enum Foo { + Bar = 123, +} +``` + +If a discriminant isn't assigned, they start at zero, and add one for each +variant, in order. + +You can cast an enum to get this value: + +``` +# enum Foo { Bar = 123 } +let x = Foo::Bar as u32; // x is now 123u32 +``` + +This only works as long as none of the variants have data attached. If +it were `Bar(i32)`, this is disallowed. + ### Constant items ```{.ebnf .gram}