generic

package
v1.7.0-dev-20191004 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: Apache-2.0 Imports: 3 Imported by: 21

Documentation

Overview

Package generic provides methods to test whether a type conforms to a generic interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	// T1Ty is the type of T1.
	T1Ty = reflect.TypeOf(T1{})

	// T2Ty is the type of T2.
	T2Ty = reflect.TypeOf(T2{})

	// T3Ty is the type of T3.
	T3Ty = reflect.TypeOf(T3{})

	// T4Ty is the type of T4.
	T4Ty = reflect.TypeOf(T4{})

	// TOTy is the type of TO.
	TOTy = reflect.TypeOf(TO{})

	// TPTy is the type of TP.
	TPTy = reflect.TypeOf(TP{})
)

Functions

This section is empty.

Types

type Any

type Any struct{}

Any is the type used for open types.

type Match

type Match struct {
	// Errors found matching the interface to the implementation.
	Errors []error

	// Bindings of generic type to matched type.
	Bindings map[reflect.Type]reflect.Type
}

Match is the result of Implements and CheckSigs.

func CheckSigs added in v1.2.0

func CheckSigs(sigs ...Sig) Match

CheckSigs checks that each function signature implements the generic interface signature. CheckSigs returns a Match which lists any generic type inconsistencies, and lists the mappings of generic types to implementation types.

func Implements

func Implements(ty, iface reflect.Type, generics ...reflect.Type) Match

Implements checks that ty implements the generic interface iface. Implements returns a Match which lists any generic type inconsistencies, and lists the mappings of generic types to implementation types. generics is a list of open types used by the generic interface iface.

func (Match) Ok

func (m Match) Ok() bool

Ok returns true if the type implemented the generic interface.

type Sig added in v1.2.0

type Sig struct {
	// Name of the function.
	Name string
	// The signature the function must match.
	Interface interface{}
	// The provided function being checked.
	Function interface{}
}

Sig is a pair of functions used for validation by CheckSigs.

type T1

type T1 struct{}

T1 is a placeholder type that can be used for generic subsitutions.

type T2

type T2 struct{}

T2 is a placeholder type that can be used for generic subsitutions.

type T3

type T3 struct{}

T3 is a placeholder type that can be used for generic subsitutions.

type T4

type T4 struct{}

T4 is a placeholder type that can be used for generic subsitutions.

type TO added in v1.2.0

type TO struct{}

TO is a placeholder type that represents the type that is being checked for interface compliance (ty parameter to Implements).

type TP added in v1.2.0

type TP struct{}

TP is a placeholder type that represents a pointer to the type that is being checked for interface compliance.

Jump to

Keyboard shortcuts

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