]> git.proxmox.com Git - rustc.git/blob - src/doc/reference/src/types/enum.md
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / doc / reference / src / types / enum.md
1 # Enumerated types
2
3 An *enumerated type* is a nominal, heterogeneous disjoint union type, denoted
4 by the name of an [`enum` item]. [^enumtype]
5
6 An [`enum` item] declares both the type and a number of *variants*, each of
7 which is independently named and has the syntax of a struct, tuple struct or
8 unit-like struct.
9
10 New instances of an `enum` can be constructed with a [struct expression].
11
12 Any `enum` value consumes as much memory as the largest variant for its
13 corresponding `enum` type, as well as the size needed to store a discriminant.
14
15 Enum types cannot be denoted *structurally* as types, but must be denoted by
16 named reference to an [`enum` item].
17
18 [^enumtype]: The `enum` type is analogous to a `data` constructor declaration in
19 ML, or a *pick ADT* in Limbo.
20
21 [`enum` item]: ../items/enumerations.md
22 [struct expression]: ../expressions/struct-expr.md