types

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 1 Imported by: 0

README

cirello.io/types

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.

func NewAffine

func NewAffine[T any](v T) *Affine[T]

func (*Affine[T]) Unwrap

func (a *Affine[T]) Unwrap() T

Unwrap returns the value and ensures that it is used at most 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.

Jump to

Keyboard shortcuts

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