enumx

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseErrorFor

func ParseErrorFor[E _U](from string) error

ParseErrorFor new parsing error for the specific enum type E.

func Scan

func Scan(src any, offset int) (int, error)

Scan parses the database value (src) into an integer and adjusts by offset.

Types

type CanBeEnum added in v0.4.8

type CanBeEnum interface {
	EnumValues() []any
}

CanBeEnum defines an interface for types that can provide value list of their enumeration values.

type DatabaseValuer added in v0.5.5

type DatabaseValuer interface {
	driver.Valuer
	sql.Scanner
}

type DriverValueOffset

type DriverValueOffset interface {
	Offset() int
}

DriverValueOffset acts as an adaptor between code and database. It provides an offset to adjust the enumeration's value during converting

type EncodingArshaler added in v0.5.5

type EncodingArshaler interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}

type Enum

type Enum[E _U] interface {
	// Values presents enum value list
	Values() []E
	// String returns the string identifier (key) of the enumeration.
	String() string
	// Text returns enum description for presents as EnumLabel
	Text() string
	// IsZero check if v is valid
	IsZero() bool

	EncodingArshaler

	DatabaseValuer
}

Enum defines an enumeration interface for mapping between `int` and `string`. It implements encoding.TextMarshaler encoding.TextUnmarshaler for network interaction, and driver.Valuer sql.Scanner for database interaction.

Jump to

Keyboard shortcuts

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