diff --git a/src/items/enumerations.md b/src/items/enumerations.md index 81b92ec96..f5b8887b6 100644 --- a/src/items/enumerations.md +++ b/src/items/enumerations.md @@ -1,5 +1,30 @@ # Enumerations +> **Syntax** +> _Enumeration_ : +>    `enum` +> [IDENTIFIER]  +> [_Generics_]? +> [_WhereClause_]? +> `{` _EnumItems_? `}` +> +> _EnumItems_ : +>    _EnumItem_ ( `,` _EnumItem_ )\* `,`? +> +> _EnumItem_ : +>    _OuterAttribute_\* +>    [IDENTIFIER] ( _EnumItemTuple_ | _EnumItemStruct_ +> | _EnumItemDiscriminant_ )? +> +> _EnumItemTuple_ : +>    `(` [_TupleFields_]? `)` +> +> _EnumItemStruct_ : +>    `{` [_StructFields_]? `}` +> +> _EnumItemDiscriminant_ : +>    `=` [_Expression_] + An _enumeration_ is a simultaneous definition of a nominal [enumerated type] as well as a set of *constructors*, that can be used to create or pattern-match values of the corresponding enumerated type. @@ -67,3 +92,10 @@ let x = Foo::Baz as u32; // x is now 123u32 This only works as long as none of the variants have data attached. If it were `Baz(i32)`, this is disallowed. + +[IDENTIFIER]: identifiers.html +[_Generics_]: items.html#type-parameters +[_WhereClause_]: items.html#type-parameters +[_Expression_]: expressions.html +[_TupleFields_]: items/structs.html +[_StructFields_]: items/structs.html