Documentation
¶
Overview ¶
Package settings provides typed groups of player preferences. Groups hold desired values; applying and persisting them is separate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cloner ¶
type Cloner[T any] interface { // Clone copies all mutable data reachable from value without mutating it. Clone(value T) T }
Cloner makes independent copies of preference values.
type Group ¶
type Group[T any] struct { // contains filtered or unexported fields }
Group holds preferences validated by the policy passed to New. Copies of a group share its state. Groups are not safe for concurrent use.
func New ¶
New constructs a group after validating initial with policy.Validator, if non-nil. It returns an error for a typed nil policy or invalid initial value.
func (*Group[T]) Set ¶
Set validates and replaces the preferences. Invalid values leave the group unchanged. Set returns an error for an uninitialized group, a nested mutation, or a group replaced by its policy.
func (*Group[T]) Update ¶
Update applies f to a copy of the current value and sets its result. It returns an error if f is nil, the group is uninitialized, or validation fails. The callback must not replace the group or mutate it through Set or Update; nested mutations return an error. Update also returns an error if called during a policy method. Callback side effects are not rolled back.
type Policy ¶
type Policy[T any] struct { // Validator checks initial and replacement values. Nil accepts all values. Validator Validator[T] // Cloner copies values at the group boundary. Nil uses an ordinary copy, // which is safe only when values contain no mutable references. Cloner Cloner[T] }
Policy defines optional validation and copying for a group. Policy methods must not replace the group. Set and Update reject mutations of the same group while a policy method is running. Other side effects are not rolled back.
type Validator ¶
type Validator[T any] interface { // Validate returns an error if value is unacceptable and does not mutate it. Validate(value T) error }
Validator decides whether a proposed preference value is acceptable.
type ValidatorFunc ¶
ValidatorFunc adapts a non-nil function to Validator.
func (ValidatorFunc[T]) Validate ¶
func (f ValidatorFunc[T]) Validate(value T) error
Validate calls f with value.