46. Enumeration traits

The enum_trait module implements typeinfo traits for the enumerations.

All functions and symbols are in “enum_trait” module, use require to get access to it.

require daslib/enum_trait

46.1. Typeinfo macros

enum_names

Implements typeinfo(enum_names EnumOrEnumType) which returns array of strings with enumValue names.

enum_length

Implements typeinfo(enum_length EnumOrEnumType) which returns total number of elements in enumeration.

46.2. Handled enumerations

string_to_enum

Enumeration annotation which implements string constructor for enumeration.

46.3. Uncategorized

string(arg: auto) : auto()
converts enum value to string

usage: let s = string(EnumValue)

Arguments
  • arg : auto

to_enum(ent: auto(EnumT); name: string) : EnumT()
converts string to enum value, panics if not found

usage: let e = to_enum(type<EnumType>,”EnumValueName”)

Arguments
  • ent : auto(EnumT)

  • name : string

to_enum(ent: auto(EnumT); name: string; defaultValue: EnumT) : EnumT()
converts string to enum value, returns defaultValue if not found

usage: let e = to_enum(type<EnumType>,”EnumValueName”, EnumType.DefaultValue)

Arguments
  • ent : auto(EnumT)

  • name : string

  • defaultValue : EnumT

enum_to_table(ent: auto(EnumT)) : table<string, EnumT>()
converts enum type to array of tuples (name, value)

usage: let t = enum_to_table(type<EnumType>)

Arguments
  • ent : auto(EnumT)