enums

package module
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: BSD-3-Clause Imports: 1 Imported by: 53

README

enums

Enums provides utilities for creating and using enumerated types in Go. There are two main parts of enums: package enums, which defines the Enum and BitFlag interfaces, and the enum code generation tool enumgen, which is based on dmarkham/enumer and stringer.

Documentation

Overview

Package enums provides common interfaces for enums and bit flag enums and utilities for using them

Package enums provides common interfaces for enums and bit flag enums and utilities for using them

Index

Constants

View Source
const (
	// Version is the version of this package being used
	Version = "v0.9.8"
	// GitCommit is the commit just before the latest version commit
	GitCommit = "879861e"
	// VersionDate is the date-time of the latest version commit in UTC (in the format 'YYYY-MM-DD HH:MM', which is the Go format '2006-01-02 15:04')
	VersionDate = "2023-09-04 03:30"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BitFlag

type BitFlag interface {
	Enum
	// Has returns whether these flags
	// have the given flag set.
	Has(f BitFlag) bool
}

BitFlag is the interface that all bit flag enum types satisfy. Bit flag enum types support all of the operations that standard enums do, and additionally can check if they have a given bit flag.

type BitFlagSetter added in v0.9.6

type BitFlagSetter interface {
	EnumSetter
	BitFlag
	// Set sets the value of the given
	// flags in these flags to the given value.
	Set(on bool, f ...BitFlag)
}

BitFlagSetter is an expanded interface that all pointers to bit flag enum types satisfy. Pointers to bit flag enum types must satisfy all of the methods of EnumSetter and BitFlag, and must also be able to set a given bit flag.

type Enum

type Enum interface {
	fmt.Stringer
	// Int64 returns the enum value as an int64.
	Int64() int64
	// Desc returns the description of the enum value.
	Desc() string
	// IsValid returns whether the value is a
	// valid option for its enum type.
	IsValid() bool
	// Values returns all possible values this
	// enum type has. This slice will be in the
	// same order as those returned by Strings and Descs.
	Values() []Enum
	// Strings returns the string representations of
	// all possible values this enum type has.
	// This slice will be in the same order as
	// those returned by Values and Descs.
	Strings() []string
	// Descs returns the descriptions of all
	// possible values this enum type has.
	// This slice will be in the same order as
	// those returned by Values and Strings.
	Descs() []string
}

Enum is the interface that all enum types satisfy. Enum types must be convertable to strings and int64s, must be able to return a description of their value, must be able to report if they are valid, and must be able to return all possible enum values and string and description representations.

type EnumSetter added in v0.9.6

type EnumSetter interface {
	Enum
	// SetString sets the enum value from its
	// string representation, and returns an
	// error if the string is invalid.
	SetString(s string) error
	// SetInt64 sets the enum value from an int64.
	SetInt64(i int64)
}

EnumSetter is an expanded interface that all pointers to enum types satisfy. Pointers to enum types must satisfy all of the methods of Enum, and must also be settable from strings and int64s.

Directories

Path Synopsis
cmd
enumgen
Package main provides the actual command line implementation of the enumgen library.
Package main provides the actual command line implementation of the enumgen library.
Package enumgen provides functions for generating enum methods for enum types.
Package enumgen provides functions for generating enum methods for enum types.
cmd
config
Package config contains the configuration information used by enumgen
Package config contains the configuration information used by enumgen

Jump to

Keyboard shortcuts

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