reflectkit

package
v0.278.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const ErrTypeMismatch errorkit.Error = "ErrTypeMismatch"

Variables

This section is empty.

Functions

func BaseTypeOf

func BaseTypeOf(i any) reflect.Type

func BaseValue

func BaseValue(v reflect.Value) reflect.Value

func BaseValueOf

func BaseValueOf(i any) reflect.Value

func Cast

func Cast[T any](v any) (T, bool)

func DerefType added in v0.274.0

func DerefType(T reflect.Type) (_ reflect.Type, depth int)

func Equal

func Equal(x, y any) bool

Equal will compare two value deeply. It looks for Equal method on the value as well. You can define how a type's value should be compared by using RegisterEqual.

Example
package main

import (
	"go.llib.dev/frameless/pkg/reflectkit"
)

func main() {
	reflectkit.Equal("a", "a") // true
	reflectkit.Equal("a", "b") // false
}

func FullyQualifiedName

func FullyQualifiedName(v any) string
Example
package main

import (
	"fmt"

	"go.llib.dev/frameless/pkg/reflectkit"
)

func main() {
	fmt.Println(reflectkit.FullyQualifiedName(Example{}))
}

type Example struct {
	Name string
}

func IsEmpty added in v0.207.0

func IsEmpty(val reflect.Value) bool

func IsNil added in v0.278.0

func IsNil(val reflect.Value) bool

func IsZero added in v0.217.0

func IsZero(val reflect.Value) bool
func Link(src, ptr any) (err error)

Link will make destination interface be linked with the src value.

func LookupField added in v0.278.0

func LookupField[FieldID StructFieldID](rStruct reflect.Value, i FieldID) (reflect.StructField, reflect.Value, bool)

func PointerOf added in v0.181.0

func PointerOf(value reflect.Value) reflect.Value

func RegisterEqual

func RegisterEqual[T any](fn func(x, y T) bool) struct{}

func SetValue

func SetValue(variable, value reflect.Value)

SetValue will force set

func SymbolicName

func SymbolicName(v any) string
Example
package main

import (
	"fmt"

	"go.llib.dev/frameless/pkg/reflectkit"
)

func main() {
	fmt.Println(reflectkit.SymbolicName(Example{}))
}

type Example struct {
	Name string
}

func ToSettable added in v0.278.0

func ToSettable(rv reflect.Value) (_ reflect.Value, ok bool)
Example
package main

import (
	"reflect"

	"go.llib.dev/frameless/pkg/reflectkit"
)

func main() {
	type T struct{ v int }
	var v T

	ptr := reflect.ValueOf(&v)
	rStruct := ptr.Elem()

	got, ok := reflectkit.ToSettable(rStruct.FieldByName("v"))
	_, _ = got, ok
}

func ToValue added in v0.261.0

func ToValue(v any) reflect.Value

func TypeOf added in v0.180.0

func TypeOf[T any](i ...T) reflect.Type

Types

type StructFieldID added in v0.278.0

type StructFieldID interface {
	reflect.StructField | int | string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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