Enums
An enum defines a nominal, unparameterized logic type with named variants mapped to explicit non-negative integer constants. For sum types whose variants carry typed payloads, see Unions & Option.
Syntax
neo
pub enum State {
Idle = 0,
Busy = 1,
Done = 2,
}Width & Bit Representation
- The bit width of an enum is
max(1, bit_length(max_variant_value)). - A 1-value enum (e.g.,
enum Single { Only = 0 }) has width1, never0. - Query at compile time via
State.width.
Validation Rules
- Enums are nominally typed: an enum value can only be assigned to or compared with (
==,!=) values of the same enum type. - Variant accessors (
State.Idleor inferred.Idle) produceConstant-timedLogicVals of typeStatecarrying their compile-time bit pattern. caseexpressions on an enum are checked for exhaustiveness (non_exhaustive_case), duplicate variant arms (duplicate_case_armwarning), unreachable_when all variants are already covered (unreachable_wildcardwarning), and non-trailing_(non_trailing_wildcardwarning).- Enum discriminants must fit in 64 bits (
<= u64::MAX, elseenum_value_out_of_range); empty enums (empty_enum) and duplicate values (duplicate_enum_value) are rejected. .castTo(T)is supported whenever Z3 provesState.width == T.width.
Elaboration & Code Generation
In neo-ir, SystemVerilog, and FIRRTL, enum signals lower to packed bit vectors of width State.width, and variant references lower to sized constant bit literals.