Documentation
¶
Index ¶
- type BothXY
- type Func
- type Lookup
- type NoXY
- type OnlyX
- type OnlyY
- type Shape
- type Type
- func (t Type) Deref() Type
- func (t Type) Identical(u Type) bool
- func (t Type) IsArray() bool
- func (t Type) IsBasic() bool
- func (t Type) IsError() bool
- func (t Type) IsGeneric() bool
- func (t Type) IsInterface() bool
- func (t Type) IsMap() bool
- func (t Type) IsNamed() bool
- func (t Type) IsNil() bool
- func (t Type) IsPointer() bool
- func (t Type) IsSlice() bool
- func (t Type) IsStruct() bool
- func (t Type) Method(name string) (*types.Func, bool)
- func (t Type) Pkg() *types.Package
- func (t Type) PointerDepth() int
- func (t Type) Pos() token.Pos
- func (t Type) Ref() Type
- func (t Type) String() string
- func (t Type) StructField(name string) (*types.Var, bool)
- func (t Type) Type() types.Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Func ¶
type Func interface {
Object() types.Object
Name() string // for declared function
FuncLit() *ast.FuncLit // for anonymous function literal
// Signature information
X() Type
Y() Type
HasErr() bool
HasOut() bool
// Position information
Pos() token.Pos
WithPos(token.Pos) Func
}
Func describes a function information. It holds function signature information of types.Object that is necessary from the Convgen's perspective.
func FuncLitOf ¶
FuncLitOf inspects the given function literal and returns a new Func. It returns an error if the function signature does not match with the given shape.
func FuncOf ¶
FuncOf inspects the given function and returns a new Func. It returns an error if the function signature does not match with the given shape.
func NewFunc ¶
NewFunc creates a new Func with the given attributes.
This is for creating a new function programmatically. It focuses on the signature of the function only, not the body.
To create from an existing function object, use FuncOf or related functions. To create from a function literal without a named object, use [InspectFuncLit] or related functions.
type Lookup ¶
type Lookup[T Func] struct { // contains filtered or unexported fields }
Lookup indexes converter functions by their input and output types.
func (*Lookup[T]) Del ¶
Del removes a function which converts X to Y. It returns whether such a function existed.
type Shape ¶
Shape is a type constraint for function shapes. It is used in FuncOf and FuncLitOf to specify which kind of function signature is expected.
Shape | Basic | HasErr | HasOut | HasErr & HasOut --------+------------+---------------------+--------------+------------------- NoXY | func() | func() error | - | - OnlyX | func(x) | func(x) error | - | - OnlyY | func() y | func() (y, error) | func(*y), | func(*y) error BothXY | func(x) y | func(x) (y, error) | func(x, *y) | func(x, *y) error
type Type ¶
type Type struct {
T types.Type
Basic *types.Basic
Array *types.Array
Slice *types.Slice
Map *types.Map
Struct *types.Struct
Interface *types.Interface
Pointer *types.Pointer
Named *types.Named
Elem *Type
Key *Type
Len int64
}
Type describes a type information. It holds information of types.Type that is necessary from the Convgen's perspective.
func (Type) Deref ¶
Deref returns the element type if the type is a pointer. For type of *X, it returns type of X. If the type is not a pointer, it returns the type itself.
func (Type) IsGeneric ¶
IsGeneric reports whether the type is generic or has any generic type parameters. Even though the type has type parameters, if all type arguments are concrete types, it returns false.
func (Type) IsInterface ¶
func (Type) Method ¶
Method returns the method with the given name. If the type is not a named type or the method does not exist, it returns nil and false.
func (Type) Pkg ¶
Pkg returns the package where the type is defined. It returns nil if the type is not a named type.
func (Type) PointerDepth ¶
PointerDepth returns the number of pointer indirections. For example, for type of ***X, it returns 3. For type of X, it returns 0.
func (Type) Pos ¶
Pos returns the position where the type is defined. It returns token.NoPos if the type is not a named type.
func (Type) StructField ¶
StructField returns the struct field with the given name. If the type is not a struct or the field does not exist, it returns nil and false.