settings

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 ClonerFunc

type ClonerFunc[T any] func(T) T

ClonerFunc adapts a non-nil function to Cloner.

func (ClonerFunc[T]) Clone

func (f ClonerFunc[T]) Clone(value T) T

Clone calls f with value.

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

func New[T any](initial T, policy Policy[T]) (*Group[T], error)

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

func (g *Group[T]) Set(value T) error

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

func (g *Group[T]) Update(f func(T) T) error

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.

func (*Group[T]) Value

func (g *Group[T]) Value() (T, error)

Value returns a copy of the preferences. It returns an error if the group was not constructed with New or is replaced by its copy policy.

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

type ValidatorFunc[T any] func(T) error

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.

Jump to

Keyboard shortcuts

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