types

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: BSD-3-Clause Imports: 0 Imported by: 3

Documentation

Overview

Package types mimics the https://golang.org/pkg/go/types/ package. It also contains some extra utility functions, they're defined in ext.go file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Identical

func Identical(x, y Type) bool

Identical reports whether x and y are identical types. Receivers of Signature types are ignored.

func Implements

func Implements(typ Type, iface *Interface) bool

Implements reports whether a given type implements the specified interface.

Types

type Array added in v0.3.1

type Array struct{}

An Array represents an array type.

func AsArray added in v0.3.1

func AsArray(x Type) *Array

AsArray is a type-assert like operation, x.(*Array), but never panics. Returns nil if type is not an array.

func NewArray added in v0.3.1

func NewArray(elem Type, len int) *Array

NewArray returns a new array type for the given element type and length. A negative length indicates an unknown length.

func (*Array) Elem added in v0.3.1

func (*Array) Elem() Type

Elem returns element type of array.

func (*Array) Len added in v0.3.1

func (*Array) Len() int

Len returns the length of array. A negative result indicates an unknown length.

func (*Array) String added in v0.3.1

func (*Array) String() string

func (*Array) Underlying added in v0.3.1

func (*Array) Underlying() Type

type Interface

type Interface struct{}

An Interface represents an interface type.

func AsInterface

func AsInterface(x Type) *Interface

AsInterface is a type-assert like operation, x.(*Interface), but never panics. Returns nil if type is not an interface.

func (*Interface) String

func (*Interface) String() string

func (*Interface) Underlying

func (*Interface) Underlying() Type

type Pointer

type Pointer struct{}

A Pointer represents a pointer type.

func AsPointer

func AsPointer(x Type) *Pointer

AsPointer is a type-assert like operation, x.(*Pointer), but never panics. Returns nil if type is not a pointer.

func NewPointer

func NewPointer(elem Type) *Pointer

NewPointer returns a new pointer type for the given element (base) type.

func (*Pointer) Elem

func (*Pointer) Elem() Type

Elem returns the element type for the given pointer.

func (*Pointer) String

func (*Pointer) String() string

func (*Pointer) Underlying

func (*Pointer) Underlying() Type

type Slice added in v0.3.1

type Slice struct{}

A Slice represents a slice type.

func AsSlice added in v0.3.1

func AsSlice(x Type) *Slice

AsSlice is a type-assert like operation, x.(*Slice), but never panics. Returns nil if type is not an array.

func NewSlice added in v0.3.1

func NewSlice(elem Type) *Slice

NewSlice returns a new slice type for the given element type.

func (*Slice) Elem added in v0.3.1

func (*Slice) Elem() Type

Elem returns element type of slice.

func (*Slice) String added in v0.3.1

func (*Slice) String() string

func (*Slice) Underlying added in v0.3.1

func (*Slice) Underlying() Type

type Struct added in v0.3.20

type Struct struct{}

A struct represents a struct type.

func AsStruct added in v0.3.20

func AsStruct(x Type) *Struct

AsStruct is a type-assert like operation, x.(*Struct), but never panics. Returns nil if type is not a struct.

func (*Struct) Field added in v0.3.20

func (*Struct) Field(i int) *Var

func (*Struct) NumFields added in v0.3.20

func (*Struct) NumFields() int

func (*Struct) String added in v0.3.21

func (*Struct) String() string

func (*Struct) Underlying added in v0.3.21

func (*Struct) Underlying() Type

type Type

type Type interface {
	// Underlying returns the underlying type of a type.
	Underlying() Type

	// String returns a string representation of a type.
	String() string
}

A Type represents a type of Go. All types implement the Type interface.

type Var added in v0.3.20

type Var struct{}

func (*Var) Embedded added in v0.3.20

func (*Var) Embedded() bool

func (*Var) Type added in v0.3.20

func (*Var) Type() Type

Jump to

Keyboard shortcuts

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