enum

package
v0.15.83 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package enum provides generic enum and bit-flag helpers (Go 1.18+ generics).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert[E Values](names ...string) E

Convert returns enum value from names. If multiple names are provided, the enum value is the bitwise OR of the values.

func FlagNames

func FlagNames[E Names](val E) []string

FlagNames returns list of enum value names from flag value

func Flags

func Flags[E Names](val E) []E

FlagsInt returns list of enum values from flag

func FlagsInt

func FlagsInt[E Names](val E) []int32

FlagsInt returns list of enum values from flag

func NamesHelpString

func NamesHelpString(vals map[string]int32) string

NamesHelpString returns supported Enum values concatenated by ","

func Parse

func Parse[E Values](val string) E

Parse returns enum value from names

func SliceDisplayNames added in v0.15.73

func SliceDisplayNames[E DisplayNames](vals []E) []string

func SliceDisplayNamesString added in v0.15.73

func SliceDisplayNamesString[E DisplayNames](vals []E) string

func SliceNames added in v0.15.73

func SliceNames[E Names](vals []E) []string

func SliceNamesString added in v0.15.73

func SliceNamesString[E Names](vals []E) string

func SupportedNames

func SupportedNames[E Values]() string

SupportedNames returns supported Enum values concatenated by ","

Types

type DisplayNames added in v0.15.73

type DisplayNames interface {
	Names
	// DisplayNamesMap returns a map of enum values to their display names
	DisplayNamesMap() map[int32]string
}

DisplayNames interface for enum with display names

type Enum

type Enum interface {
	~int32
}

Enum interface for generic enum

type Names added in v0.9.48

type Names interface {
	Enum
	// NamesMap returns a map of enum values to their names
	NamesMap() map[int32]string
}

Names interface for enum with names

type ProtoEnum added in v0.15.77

type ProtoEnum interface {
	String() string
	Descriptor() protoreflect.EnumDescriptor
	Number() protoreflect.EnumNumber
}

type Values added in v0.9.48

type Values interface {
	Enum
	// ValuesMap returns a map of enum names to their values
	ValuesMap() map[string]int32
}

Values interface for enum with values

Jump to

Keyboard shortcuts

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