Module starlark::values::enumeration
source · Expand description
Fixed set enumerations, with runtime checking of validity.
Calling enum()
produces an EnumType
. Calling the EnumType
creates an EnumValue
.
The implementation ensures that each value of the enumeration is only stored once,
so they may also provide (modest) memory savings. Created in starlark with the
enum
function:
Colors = enum("Red", "Green", "Blue")
val = Colors("Red")
assert_eq(val.value, "Red")
assert_eq(val.index, 0)
assert_eq(Colors[0], val)
assert_eq(Colors.type, "Colors")
assert_eq([v.value for v in Colors], ["Red", "Green", "Blue"])
Type Aliases§
- Unfrozen enum type.
- Type of value.
- Frozen enum type.
- Type of frozen value.