Documentation
¶
Index ¶
- Constants
- func Copy(dst, src Value) int
- func DeepEqual(x, y interface{}) bool
- func Swapper(slice interface{}) func(i, j int)
- type ChanDir
- type Kind
- type MapIter
- type Method
- type SelectCase
- type SelectDir
- type SliceHeaderdeprecated
- type StringHeaderdeprecated
- type StructField
- type StructTag
- type Type
- type Value
- func Append(v Value, x ...Value) Value
- func AppendSlice(s, t Value) Value
- func Indirect(v Value) Value
- func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value
- func MakeMap(typ Type) Value
- func MakeMapWithSize(typ Type, n int) Value
- func MakeSlice(typ Type, len, cap int) Value
- func New(typ Type) Value
- func NewAt(typ Type, p unsafe.Pointer) Value
- func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)
- func ValueOf(i interface{}) Value
- func Zero(typ Type) Value
- func (v Value) Addr() Value
- func (v Value) Call(in []Value) []Value
- func (v Value) CallSlice(in []Value) []Value
- func (v Value) CanConvert(t Type) bool
- func (v Value) Close()
- func (v Value) Convert(t Type) Value
- func (v Value) Elem() Value
- func (v Value) Equal(u Value) bool
- func (v Value) Field(i int) Value
- func (v Value) FieldByIndex(index []int) Value
- func (v Value) FieldByIndexErr(index []int) (Value, error)
- func (v Value) FieldByName(name string) Value
- func (v Value) FieldByNameFunc(match func(string) bool) Value
- func (v Value) Index(i int) Value
- func (v Value) MapIndex(key Value) Value
- func (v Value) MapKeys() []Value
- func (v Value) MapRange() *MapIter
- func (v Value) Method(i int) Value
- func (v Value) MethodByName(name string) Value
- func (v Value) Recv() (x Value, ok bool)
- func (v Value) Send(x Value)
- func (v Value) Seq() iter.Seq[Value]
- func (v Value) Seq2() iter.Seq2[Value, Value]
- func (v Value) Set(x Value)
- func (v Value) SetIterKey(iter *MapIter)
- func (v Value) SetIterValue(iter *MapIter)
- func (v Value) SetMapIndex(key, elem Value)
- func (v Value) Slice(i, j int) Value
- func (v Value) Slice3(i, j, k int) Value
- func (v Value) Type() Type
- type ValueError
Constants ¶
const ( RecvDir = reflectlite.RecvDir SendDir = reflectlite.SendDir BothDir = reflectlite.BothDir )
const Ptr = reflectlite.Ptr
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChanDir ¶ added in v0.23.0
type ChanDir = reflectlite.ChanDir
type Kind ¶
type Kind = reflectlite.Kind
const ( Invalid Kind = reflectlite.Invalid Bool Kind = reflectlite.Bool Int Kind = reflectlite.Int Int8 Kind = reflectlite.Int8 Int16 Kind = reflectlite.Int16 Int32 Kind = reflectlite.Int32 Int64 Kind = reflectlite.Int64 Uint Kind = reflectlite.Uint Uint8 Kind = reflectlite.Uint8 Uint16 Kind = reflectlite.Uint16 Uint32 Kind = reflectlite.Uint32 Uint64 Kind = reflectlite.Uint64 Uintptr Kind = reflectlite.Uintptr Float32 Kind = reflectlite.Float32 Float64 Kind = reflectlite.Float64 Complex64 Kind = reflectlite.Complex64 Complex128 Kind = reflectlite.Complex128 Array Kind = reflectlite.Array Chan Kind = reflectlite.Chan Func Kind = reflectlite.Func Interface Kind = reflectlite.Interface Map Kind = reflectlite.Map Pointer Kind = reflectlite.Pointer Slice Kind = reflectlite.Slice String Kind = reflectlite.String Struct Kind = reflectlite.Struct UnsafePointer Kind = reflectlite.UnsafePointer )
type MapIter ¶ added in v0.5.0
type MapIter reflectlite.MapIter
type Method ¶ added in v0.23.0
type Method struct { // Name is the method name. Name string // PkgPath is the package path that qualifies a lower case (unexported) // method name. It is empty for upper case (exported) method names. // The combination of PkgPath and Name uniquely identifies a method // in a method set. // See https://golang.org/ref/spec#Uniqueness_of_identifiers PkgPath string Type Type // method type Func Value // func with receiver as first argument Index int // index for Type.Method }
Method represents a single method.
type SelectCase ¶ added in v0.28.0
type SelectDir ¶ added in v0.28.0
type SelectDir int
const ( SelectSend SelectDir // case Chan <- Send SelectRecv // case <-Chan: SelectDefault // default )
type SliceHeader
deprecated
type SliceHeader struct { Data uintptr Len intw Cap intw }
Deprecated: Use unsafe.Slice or unsafe.SliceData instead.
type StringHeader
deprecated
type StringHeader struct { Data uintptr Len intw }
Deprecated: Use unsafe.String or unsafe.StringData instead.
type StructField ¶
type StructField struct { // Name indicates the field name. Name string // PkgPath is the package path where the struct containing this field is // declared for unexported fields, or the empty string for exported fields. PkgPath string Type Type Tag StructTag // field tag string Offset uintptr Index []int // index sequence for Type.FieldByIndex Anonymous bool }
A StructField describes a single field in a struct. This must be kept in sync with reflectlite.StructField.
func VisibleFields ¶ added in v0.28.0
func VisibleFields(t Type) []StructField
func (StructField) IsExported ¶ added in v0.20.0
func (f StructField) IsExported() bool
IsExported reports whether the field is exported.
type StructTag ¶ added in v0.14.0
type StructTag = reflectlite.StructTag
type Type ¶
type Type interface { // Align returns the alignment in bytes of a value of // this type when allocated in memory. Align() int // FieldAlign returns the alignment in bytes of a value of // this type when used as a field in a struct. FieldAlign() int // Method returns the i'th method in the type's method set. // It panics if i is not in the range [0, NumMethod()). // // For a non-interface type T or *T, the returned Method's Type and Func // fields describe a function whose first argument is the receiver. // // For an interface type, the returned Method's Type field gives the // method signature, without a receiver, and the Func field is nil. // // Only exported methods are accessible and they are sorted in // lexicographic order. Method(int) Method // MethodByName returns the method with that name in the type's // method set and a boolean indicating if the method was found. // // For a non-interface type T or *T, the returned Method's Type and Func // fields describe a function whose first argument is the receiver. // // For an interface type, the returned Method's Type field gives the // method signature, without a receiver, and the Func field is nil. MethodByName(string) (Method, bool) // NumMethod returns the number of exported methods in the type's method set. NumMethod() int // 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 // 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 // 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 // ConvertibleTo reports whether a value of the type is convertible to type u. ConvertibleTo(u Type) bool // Comparable reports whether values of this type are comparable. Comparable() bool // Bits returns the size of the type in bits. // It panics if the type's Kind is not one of the // sized or unsized Int, Uint, Float, or Complex kinds. Bits() int // ChanDir returns a channel type's direction. // It panics if the type's Kind is not Chan. ChanDir() ChanDir // IsVariadic reports whether a function type's final input parameter // is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's // implicit actual type []T. // // For concreteness, if t represents func(x int, y ... float64), then // // t.NumIn() == 2 // t.In(0) is the reflect.Type for "int" // t.In(1) is the reflect.Type for "[]float64" // t.IsVariadic() == true // // IsVariadic panics if the type's Kind is not Func. IsVariadic() bool // Elem returns a type's element type. // It panics if the type's Kind is not Array, Chan, Map, Pointer, or Slice. Elem() Type // Field returns a struct type's i'th field. // It panics if the type's Kind is not Struct. // It panics if i is not in the range [0, NumField()). Field(i int) StructField // FieldByIndex returns the nested field corresponding // to the index sequence. It is equivalent to calling Field // successively for each index i. // It panics if the type's Kind is not Struct. FieldByIndex(index []int) StructField // FieldByName returns the struct field with the given name // and a boolean indicating if the field was found. FieldByName(name string) (StructField, bool) // FieldByNameFunc returns the struct field with a name // that satisfies the match function and a boolean indicating if // the field was found. // // FieldByNameFunc considers the fields in the struct itself // and then the fields in any embedded structs, in breadth first order, // stopping at the shallowest nesting depth containing one or more // fields satisfying the match function. If multiple fields at that depth // satisfy the match function, they cancel each other // and FieldByNameFunc returns no match. // This behavior mirrors Go's handling of name lookup in // structs containing embedded fields. FieldByNameFunc(match func(string) bool) (StructField, bool) // In returns the type of a function type's i'th input parameter. // It panics if the type's Kind is not Func. // It panics if i is not in the range [0, NumIn()). In(i int) Type // Key returns a map type's key type. // It panics if the type's Kind is not Map. Key() Type // Len returns an array type's length. // It panics if the type's Kind is not Array. Len() int // NumField returns a struct type's field count. // It panics if the type's Kind is not Struct. NumField() int // NumIn returns a function type's input parameter count. // It panics if the type's Kind is not Func. NumIn() int // NumOut returns a function type's output parameter count. // It panics if the type's Kind is not Func. NumOut() int // Out returns the type of a function type's i'th output parameter. // It panics if the type's Kind is not Func. // It panics if i is not in the range [0, NumOut()). Out(i int) Type // OverflowComplex reports whether the complex128 x cannot be represented by type t. // It panics if t's Kind is not Complex64 or Complex128. OverflowComplex(x complex128) bool // OverflowFloat reports whether the float64 x cannot be represented by type t. // It panics if t's Kind is not Float32 or Float64. OverflowFloat(x float64) bool // OverflowInt reports whether the int64 x cannot be represented by type t. // It panics if t's Kind is not Int, Int8, Int16, Int32, or Int64. OverflowInt(x int64) bool // OverflowUint reports whether the uint64 x cannot be represented by type t. // It panics if t's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64. OverflowUint(x uint64) bool // CanSeq reports whether a [Value] with this type can be iterated over using [Value.Seq]. CanSeq() bool // CanSeq2 reports whether a [Value] with this type can be iterated over using [Value.Seq2]. CanSeq2() bool }
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 {
reflectlite.Value
}
func Append ¶ added in v0.14.0
Append appends the values x to a slice s and returns the resulting slice. As in Go, each x's value must be assignable to the slice's element type.
func AppendSlice ¶ added in v0.19.0
AppendSlice appends a slice t to a slice s and returns the resulting slice. The slices s and t must have the same element type.
func MakeMapWithSize ¶ added in v0.28.0
MakeMapWithSize creates a new map with the specified type and initial space for approximately n elements.
func New ¶ added in v0.7.0
New is the reflect equivalent of the new(T) keyword, returning a pointer to a new value of the given type.
func Select ¶ added in v0.28.0
func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)
func (Value) CanConvert ¶ added in v0.28.0
func (Value) FieldByIndex ¶ added in v0.14.0
FieldByIndex returns the nested field corresponding to index.
func (Value) FieldByIndexErr ¶ added in v0.23.0
FieldByIndexErr returns the nested field corresponding to index.
func (Value) FieldByName ¶ added in v0.14.0
func (Value) FieldByNameFunc ¶ added in v0.29.0
func (Value) MethodByName ¶ added in v0.23.0
func (Value) Seq ¶ added in v0.37.0
Seq returns an iter.Seq[Value] that loops over the elements of v. If v's kind is Func, it must be a function that has no results and that takes a single argument of type func(T) bool for some type T. If v's kind is Pointer, the pointer element type must have kind Array. Otherwise v's kind must be Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr, Array, Chan, Map, Slice, or String.
func (Value) Seq2 ¶ added in v0.37.0
Seq2 returns an iter.Seq2[Value, Value] that loops over the elements of v. If v's kind is Func, it must be a function that has no results and that takes a single argument of type func(K, V) bool for some type K, V. If v's kind is Pointer, the pointer element type must have kind Array. Otherwise v's kind must be Array, Map, Slice, or String.
func (Value) SetIterKey ¶ added in v0.37.0
func (Value) SetIterValue ¶ added in v0.37.0
func (Value) SetMapIndex ¶ added in v0.14.0
type ValueError ¶
type ValueError = reflectlite.ValueError