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

Enum

Enums work similarly to enums in most languages (like C & Rust) and generates a native enum as the output.

Each property in the node body defines a variant and at least one must be defined. When a variant doesn’t specify a number value, it will be incremented by one from the previous variant or be zero when it’s the first variant.

The bit size of the enum is automatically determined based on the variants of the enum and the base type. Any field that uses the enum as conversion type must have the same base type as the enum.

An enum that covers all bit patterns for its bit size can be used for infallible conversion. This is possible by having a variant for each bit pattern or by having a default or catch-all variant.

An enum with a default value will collapse the value into the default if the value is not expressed by any other variant. A catch-all catches the value and retains it. You should prefer using a default value and only use catch-all when you require reflexivity.

Example

/// doc comment line
enum Example -> uint {
    /// doc comment line
    Any: _,
}

Table

PropertyValue
Identifier namespaceType
Supports repeatno
Supports basetypeyes
Supports conversion typeno
Supports short propertiesno
Supports propertiesyes, see below
Supports subnodesno

Long properties

These properties are specified in the node body.

any name

Defines a variant for the enum. The name of the property becomes the variant name.

// auto
*any name*: _,
// number
*any name*: 0,
// default number
*any name*: default 0,
// default auto
*any name*: default _,
// catch-all number
*any name*: catch-all 0,
// catch-all auto
*any name*: catch-all _

Info

  • required: no
  • multiple allowed: yes
  • supports doc comments: yes