Closed
Description
A non-exhaustive enum is an enum that may have other unknown members.
This can help create APIs that may be extended in future. This sort of thing frequently comes up in data formats, network protocols, and even C APIs.
Possible syntax:
- a non-exhaustive enum is created by including
_
as a trailing field.
Semantics:
- A non-exhaustive enum must have the size specified:
enum(u5) { X, Y, Z, _ }
- If you specify
_
when an enum is already "full" (e.g. if it'su2
and you specify 4 values followed by a_
), then there is a compiler error. - When
switch
-ed on, anelse
clause is always required @intToEnum
can never fail withhas no tag matching integer value
builtin.Enum
gains a new boolean fieldis_exhaustive
Related