typetraits

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: 0BSD Imports: 0 Imported by: 0

Documentation

Overview

Package typetraits provides traits that can be used to restrict behaviour.

The size of the types defined in this package is guaranteed to be zero and have no behaviour, which eliminates runtime overhead or memory misalignment concerns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoCompare

type NoCompare struct {
	// contains filtered or unexported fields
}

NoCompare can be embedded or nested into a struct to prevent comparison. Comparison attempts will cause a compilation error.

The size of this struct is guaranteed to be zero.

Example:

type T struct {
	_ typetraits.NoCompare
}

T{} == T{} // Comparison: compilation error!

type NoCopy

type NoCopy struct {
	// contains filtered or unexported fields
}

NoCopy can be embedded or nested into a struct to protect against copying. Copy attempts will be flagged by the copylocks analysis in go vet.

The size of this struct is guaranteed to be zero.

Example:

type T struct {
	_ typetraits.NoCopy
}

x := T{} // The initial assignment is OK.
y := x   // Copy: vetting error!

Jump to

Keyboard shortcuts

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