Documentation
¶
Overview ¶
Package reflectutil provides utility functions for the reflect package.
Index ¶
- func Compare(a, b reflect.Value) int
- func ConvertValueCanInterface(v reflect.Value) (reflect.Value, bool)
- func GetCompareFunc(typ reflect.Type) func(a, b reflect.Value) int
- func TryValueInterface(v reflect.Value) (any, bool)
- func TryValueInterfaceFor[T any](v reflect.Value) (T, bool)
- func TypeFullName(typ reflect.Type) string
- func TypeFullNameFor[T any]() string
- func ValueInterfaceFor[T any](v reflect.Value) T
- type MapEntries
- type MapEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertValueCanInterface ¶ added in v0.6.0
ConvertValueCanInterface attempts to converts a reflect.Value so it can be used with reflect.Value.Interface.
The returned boolean indicates if the conversion was successful.
If the conversion was successful, the returned reflect.Value can be used with reflect.Value.Interface. If the conversion was not successful, the returned reflect.Value is the same as the input reflect.Value.
func GetCompareFunc ¶ added in v0.7.7
GetCompareFunc returns a function that compares two values of the given type.
It panics if the type is not supported.
func TryValueInterface ¶ added in v0.6.0
TryValueInterface calls ConvertValueCanInterface and reflect.Value.Interface.
func TryValueInterfaceFor ¶ added in v0.6.0
TryValueInterfaceFor calls ConvertValueCanInterface and ValueInterfaceFor.
func TypeFullName ¶
TypeFullName returns the full name of the type.
It contains the full package path if the type is defined in a package.
func TypeFullNameFor ¶
TypeFullNameFor returns the full name of type parameter.
func ValueInterfaceFor ¶ added in v0.6.0
ValueInterfaceFor calls reflect.Value.Interface and returns the result as the specified type.
The caller must ensure that the type is correct.
Types ¶
type MapEntries ¶ added in v0.7.7
type MapEntries []MapEntry
MapEntries is a slice of MapEntry.
func GetMapEntries ¶ added in v0.7.7
func GetMapEntries(m reflect.Value) MapEntries
GetMapEntries returns the entries of a map.
func GetSortedMap ¶ added in v0.7.7
func GetSortedMap(m reflect.Value) MapEntries
GetSortedMap returns a sorted MapEntries of the given map.
func (MapEntries) Release ¶ added in v0.7.7
func (es MapEntries) Release()
Release releases the MapEntries.
It helps to reduce memory allocations.