Documentation ¶
Index ¶
- type Enum
- func (e Enum) ID() T
- func (e Enum) MarshalJSON() ([]byte, error)
- func (e Enum) MarshalText() ([]byte, error)
- func (e Enum) Name() string
- func (e *Enum) Scan(value any) error
- func (e Enum) String() string
- func (e *Enum) UnmarshalJSON(data []byte) error
- func (e *Enum) UnmarshalText(text []byte) error
- func (e *Enum) Valid() bool
- func (e Enum) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Enum ¶
type Enum[T constraints.Integer] struct { // contains filtered or unexported fields }
Enum represents a named Enum that is associaterd with an ID. Enum IDs are auto-generated starting from 0 and monotonically increasing in declaration order. The zero value of an Enum is not valid. It is safe to use this type to create other types (type OtherType Enum[MyEnumType]) as it does not implement any methods itself and, instead, delegates all methods to embedded types.
func EnumByTypeAndName ¶
func EnumByTypeAndName[T constraints.Integer](name string) (Enum[T], error)
EnumByTypeAndName returns the enum associated with the given type and name. If there is no such enum, a non-nil error is returned.
func EnumsByType ¶
func EnumsByType[T constraints.Integer]() []Enum[T]
EnumsByType returns all enums associated with the given type T.
func New ¶
func New[T constraints.Integer](name string) Enum[T]
New returns a new Enum associated with the given name and type T.
func (Enum) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Enum) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Enum) Name ¶
func (e Enum) Name() string
Name returns the name associated with this Enum instance.
func (*Enum) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Enum) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.