Documentation
¶
Overview ¶
Package register provides functionality for optional registration of types.
Index ¶
- Variables
- type AtMostOnce
- func (o *AtMostOnce[T]) Get() T
- func (o *AtMostOnce[T]) MustRegister(v T)
- func (o *AtMostOnce[T]) Register(v T) error
- func (o *AtMostOnce[T]) Registered() bool
- func (o *AtMostOnce[T]) TempClear(fn func() error) error
- func (o *AtMostOnce[T]) TempOverride(with T, fn func() error) error
- func (o *AtMostOnce[T]) TestOnlyClear()
Constants ¶
This section is empty.
Variables ¶
var ErrReRegistration = errors.New("re-registration")
ErrReRegistration is returned on all but the first of calls to AtMostOnce.Register.
Functions ¶
This section is empty.
Types ¶
type AtMostOnce ¶
type AtMostOnce[T any] struct { // contains filtered or unexported fields }
An AtMostOnce allows zero or one registration of a T.
func (*AtMostOnce[T]) Get ¶
func (o *AtMostOnce[T]) Get() T
Get returns the registered value. It MUST NOT be called before AtMostOnce.Register.
func (*AtMostOnce[T]) MustRegister ¶
func (o *AtMostOnce[T]) MustRegister(v T)
MustRegister is equivalent to AtMostOnce.Register, panicking on error.
func (*AtMostOnce[T]) Register ¶
func (o *AtMostOnce[T]) Register(v T) error
Register registers `v` or returns ErrReRegistration if already called.
func (*AtMostOnce[T]) Registered ¶
func (o *AtMostOnce[T]) Registered() bool
Registered reports whether AtMostOnce.Register has been called.
func (*AtMostOnce[T]) TempClear ¶
func (o *AtMostOnce[T]) TempClear(fn func() error) error
TempClear calls `fn`, clearing any registered `T`, but only for the life of the call. It is not threadsafe.
It is valid to call this method with or without a prior call to AtMostOnce.Register.
func (*AtMostOnce[T]) TempOverride ¶
func (o *AtMostOnce[T]) TempOverride(with T, fn func() error) error
TempOverride calls `fn`, overriding any registered `T`, but only for the life of the call. It is not threadsafe.
It is valid to call this method with or without a prior call to AtMostOnce.Register.
func (*AtMostOnce[T]) TestOnlyClear ¶
func (o *AtMostOnce[T]) TestOnlyClear()
TestOnlyClear clears any previously registered value, returning `o` to its default state. It panics if called from a non-testing call stack.