Documentation
¶
Index ¶
- func NewHolders[T privateType]() (*EnumHolderPublic[T], *EnumHolderPrivate[T])
- func SetPanicOnUnexistedValues(panic bool)
- type BaseType
- type EnumHolderPrivate
- type EnumHolderPublic
- type EnumValue
- func (enum EnumValue[T]) Int() int
- func (enum EnumValue[T]) MarshalBinary() (data []byte, err error)
- func (enum EnumValue[T]) MarshalText() ([]byte, error)
- func (enum EnumValue[T]) String() string
- func (enum *EnumValue[T]) UnmarshalBinary(data []byte) error
- func (enum *EnumValue[T]) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHolders ¶
func NewHolders[T privateType]() (*EnumHolderPublic[T], *EnumHolderPrivate[T])
NewHolders must be called ini init state/thread only It return two holders: public and private. public holder can assign to public global values - it is safe from used by external code: check values, get all possible values, fast conversion to string, etc. private holder must be assigned to private value (usually global) it will use for define expected values and access to Unsafe... methods if need.
func SetPanicOnUnexistedValues ¶
func SetPanicOnUnexistedValues(panic bool)
Types ¶
type EnumHolderPrivate ¶
type EnumHolderPrivate[T privateType] struct { *EnumHolderPublic[T] }
func (*EnumHolderPrivate[T]) New ¶
func (h *EnumHolderPrivate[T]) New(val int, name string) EnumValue[T]
New must call only from init state/goroutine
func (*EnumHolderPrivate[T]) UnsafeFromInt ¶
func (h *EnumHolderPrivate[T]) UnsafeFromInt(val int) EnumValue[T]
UnsafeFromInt create EnumValue value with raw val without check. val MUST be valid raw value for type - value, created by UnsafeFromInt has not guaranties about correct internal value it need only for optimization of hot way, when val can checked by external code.
type EnumHolderPublic ¶
type EnumHolderPublic[T privateType] struct {
// contains filtered or unexported fields
}
func (*EnumHolderPublic[T]) All ¶
func (h *EnumHolderPublic[T]) All() []EnumValue[T]
All return all available enum values in int value order
func (*EnumHolderPublic[T]) FromInt ¶
func (h *EnumHolderPublic[T]) FromInt(val int) (EnumValue[T], error)
func (*EnumHolderPublic[T]) FromString ¶
func (h *EnumHolderPublic[T]) FromString(s string) (EnumValue[T], error)
func (*EnumHolderPublic[T]) ValueToString ¶
func (h *EnumHolderPublic[T]) ValueToString(v EnumValue[T]) string
type EnumValue ¶
type EnumValue[T privateType] struct {
// contains filtered or unexported fields
}
func (EnumValue[T]) MarshalBinary ¶ added in v0.0.3
MarshalBinary implements https://pkg.go.dev/encoding#BinaryMarshaler
func (EnumValue[T]) MarshalText ¶ added in v0.0.3
MarshalText implements https://pkg.go.dev/encoding#TextMarshaler
func (*EnumValue[T]) UnmarshalBinary ¶ added in v0.0.3
func (*EnumValue[T]) UnmarshalText ¶ added in v0.0.3
UnmarshalText implements https://pkg.go.dev/encoding#TextUnmarshaler