Enum

package
v0.0.0-...-7db9c1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package Enum provides a way to define enums.

type MyEnum Enum.Int[struct {
	One MyEnum `gd:"ONE"`
	Two MyEnum `gd:"TWO"`
}]

var MyEnums = Enum.Values[MyEnum]()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Values

func Values[T isEnum[V], V any]() V

Values returns the available values for an enum. It should be stored and reused inside a global variable.

Types

type Any

type Any interface {
	Int() int
	Enum(yield func(string, int) bool)
}

Any integer enum should implement this interface.

type Int

type Int[T any] struct {
	// contains filtered or unexported fields
}

Int is an enum backed by an increasing integer. T should be a struct with fields of the defined type.

func (Int) Enum

func (m Int) Enum(yield func(string, int) bool)

func (Int) Int

func (m Int) Int() int

func (Int) MarshalText

func (m Int) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Int) SetInt

func (m *Int) SetInt(i int)

func (Int) String

func (m Int) String() string

String returns the name of the enum value or an empty string if the value is not defined.

func (*Int) UnmarshalText

func (m *Int) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Pointer

type Pointer interface {
	Any

	SetInt(int)
}

Pointer to any enum.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL