Documentation ¶
Overview ¶
Package reflectlite implements lightweight version of reflect, not using any package except for "runtime" and "unsafe".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Kind ¶
type Kind uint
A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.
type Type ¶
type Type interface { // Name returns the type's name within its package for a defined type. // For other (non-defined) types it returns the empty string. Name() string // PkgPath returns a defined type's package path, that is, the import path // that uniquely identifies the package, such as "encoding/base64". // If the type was predeclared (string, error) or not defined (*T, struct{}, // []int, or A where A is an alias for a non-defined type), the package path // will be the empty string. PkgPath() string // Size returns the number of bytes needed to store // a value of the given type; it is analogous to unsafe.Sizeof. Size() uintptr // Kind returns the specific kind of this type. Kind() Kind // Implements reports whether the type implements the interface type u. Implements(u Type) bool // AssignableTo reports whether a value of the type is assignable to type u. AssignableTo(u Type) bool // Comparable reports whether values of this type are comparable. Comparable() bool // String returns a string representation of the type. // The string representation may use shortened package names // (e.g., base64 instead of "encoding/base64") and is not // guaranteed to be unique among types. To test for type identity, // compare the Types directly. String() string // Elem returns a type's element type. // It panics if the type's Kind is not Ptr. Elem() Type // contains filtered or unexported methods }
Type is the representation of a Go type.
Not all methods apply to all kinds of types. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of type before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run-time panic.
Type values are comparable, such as with the == operator, so they can be used as map keys. Two Type values are equal if they represent identical types.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is the reflection interface to a Go value.
Not all methods apply to all kinds of values. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of value before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run time panic.
The zero Value represents no value. Its IsValid method returns false, its Kind method returns Invalid, its String method returns "<invalid Value>", and all other methods panic. Most functions and methods never return an invalid value. If one does, its documentation states the conditions explicitly.
A Value can be used concurrently by multiple goroutines provided that the underlying Go value can be used concurrently for the equivalent direct operations.
To compare two Values, compare the results of the Interface method. Using == on two Values does not compare the underlying values they represent.
func ValueOf ¶
func ValueOf(i interface{}) Value
ValueOf returns a new Value initialized to the concrete value stored in the interface i. ValueOf(nil) returns the zero Value.
func (Value) CanSet ¶
CanSet reports whether the value of v can be changed. A Value can be changed only if it is addressable and was not obtained by the use of unexported struct fields. If CanSet returns false, calling Set or any type-specific setter (e.g., SetBool, SetInt) will panic.
func (Value) Elem ¶
Elem returns the value that the interface v contains or that the pointer v points to. It panics if v's Kind is not Interface or Ptr. It returns the zero Value if v is nil.
func (Value) IsNil ¶
IsNil reports whether its argument v is nil. The argument must be a chan, func, interface, map, pointer, or slice value; if it is not, IsNil panics. Note that IsNil is not always equivalent to a regular comparison with nil in Go. For example, if v was created by calling ValueOf with an uninitialized interface variable i, i==nil will be true but v.IsNil will panic as v will be the zero Value.
func (Value) IsValid ¶
IsValid reports whether v represents a value. It returns false if v is the zero Value. If IsValid returns false, all other methods except String panic. Most functions and methods never return an invalid Value. If one does, its documentation states the conditions explicitly.
func (Value) Kind ¶
Kind returns v's Kind. If v is the zero Value (IsValid returns false), Kind returns Invalid.
func (Value) Len ¶
Len returns v's length. It panics if v's Kind is not Array, Chan, Map, Slice, or String.
type ValueError ¶
A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method.
func (*ValueError) Error ¶
func (e *ValueError) Error() string