Documentation
¶
Overview ¶
Package register provides functionality for optional registration of types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
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]) 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.
Click to show internal directories.
Click to hide internal directories.