pragma

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pragma provides types that can be embedded into a struct to statically enforce or prevent certain language properties. The key observation and some code (shr) is borrowed from https://github.com/protocolbuffers/protobuf-go/blob/v1.25.0/internal/pragma/pragma.go

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyChecker added in v0.0.96

type CopyChecker uintptr

CopyChecker holds back pointer to itself to detect object copying. Deprecated. use DoNotCopy instead, check by go vet. methods Copied or Check return not copied if none of methods Copied or Check have bee called before

Example
Output:

a copied : false
a copied : false
a copied : false
b copied : true

func (*CopyChecker) Check added in v0.0.96

func (c *CopyChecker) Check()

Check panic is c is copied

func (*CopyChecker) Copied added in v0.0.96

func (c *CopyChecker) Copied() bool

Copied returns true if this object is copied

type DoNotCompare

type DoNotCompare [0]func()

DoNotCompare can be embedded in a struct to prevent comparability.

Example
Output:

Invalid operation: a == b (operator == is not defined on DoNotCompare)

type DoNotCopy

type DoNotCopy [0]sync.Mutex

DoNotCopy can be embedded in a struct to help prevent shallow copies. This does not rely on a Go language feature, but rather a special case within the vet checker.

See https://golang.org/issues/8005.

Example
Output:

Assignment copies lock value to '_': type 'DoNotCopy' contains 'sync.Mutex' which is 'sync.Locker'

type DoNotImplement

type DoNotImplement interface{ ProtoInternal(doNotImplement) }
Example
Output:

cannot use &a (type *DoNotImplementStruct) as type DoNotImplement in assignment:

type NoUnkeyedLiterals

type NoUnkeyedLiterals struct{}

NoUnkeyedLiterals can be embedded in a struct to prevent unkeyed literals.

Example
Output:

cannot convert "Name" (untyped string constant) to pragma.NoUnkeyedLiterals

Jump to

Keyboard shortcuts

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