Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Enumeration Type

Like all type expressions, this expression produces a value of the type type.

Enumeration-typed values are one of a finite set of variants determined by the specific enumeration type. A variant may carry a payload value.

Each enumeration declaration introduces a new enumeration type. Each variant declared by an enumeration is a compile-time entity of that enumeration's type: a variant cannot be evaluated as a runtime value, and may only be used to construct a value or as a match pattern.

Assertions

  1. An enumeration declares at most 256 variants.

Representation

Values of an enumeration type are represented as:

  1. a u8 tag distinguishing the variant; and
  2. a union of the possible payloads for the specific enumeration type.

Lookup Scope

Each enumeration type's variants are resolved as members of the enumeration type value itself: the static access operation on a value of the type type which denotes an enumeration type resolves its provided identifier to that enumeration's variant of the same name.

Syntax

Produced by the reference expression when the referenced symbol is an enumeration type.