Documentation
¶
Overview ¶
Package types provides linear and affine types that can be used to ensure that values are used exactly once or at most once. This is useful for managing resources and ensuring that they are not used after they have been released.
This package uses panics to indicate that a certain type has been used incorrectly, and therefore it should indicate that somewhere there is a correctness issue in need of fix.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Affine ¶
type Affine[T any] struct { // contains filtered or unexported fields }
Affine is a affine typed value that can be at most used once.
type LinearDeferType ¶
type LinearDeferType[T any] struct { // contains filtered or unexported fields }
LinearDeferType is a linear typed value that can only be used once. You must call Check and the end of expected lifetime of the value to ensure that it is used exactly once.
func Linear ¶
func Linear[T any](v T) *LinearDeferType[T]
func (*LinearDeferType[T]) Check ¶
func (l *LinearDeferType[T]) Check()
func (*LinearDeferType[T]) Unwrap ¶
func (l *LinearDeferType[T]) Unwrap() T
Unwrap returns the value and ensures that it is used exactly once.
type LinearTypeGC ¶
type LinearTypeGC[T any] struct { // contains filtered or unexported fields }
LinearTypeGC is a linear typed value that can only be used once. It relied on runtime.AddCleanup to ensure that the value is used exactly once.
func LinearGC ¶
func LinearGC[T any](v T) *LinearTypeGC[T]
func (*LinearTypeGC[T]) Unwrap ¶
func (l *LinearTypeGC[T]) Unwrap() T
Unwrap returns the value and ensures that it is used exactly once.