reflectwalk

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Overview

reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements.

this fork is derived from Mitchell Hashimoto work (see LICENSE file) https://github.com/mitchellh/reflectwalk

it is adapted to maximize performance in the context of gnark circuits and remove un-needed features.

Index

Constants

This section is empty.

Variables

View Source
var ErrSkipEntry = errors.New("skip this entry")

ErrSkipEntry can be returned from walk functions to skip walking the value of this field. This is only valid in the following functions:

  • Struct: skips all fields from being walked
  • StructField: skips walking the struct value

Functions

func Walk

func Walk(data, walker interface{}) (err error)

Walk takes an arbitrary value and an interface and traverses the value, calling callbacks on the interface if they are supported. The interface should implement one or more of the walker interfaces in this package, such as PrimitiveWalker, StructWalker, etc.

Types

type ArrayWalker

type ArrayWalker interface {
	Array(reflect.Value) error
	ArrayElem(int, reflect.Value) error
}

ArrayWalker implementations are able to handle array elements found within complex structures.

type EnterExitWalker

type EnterExitWalker interface {
	Enter(Location) error
	Exit(Location) error
}

EnterExitWalker implementations are notified before and after they walk deeper into complex structures (into struct fields, into slice elements, etc.)

type InterfaceWalker

type InterfaceWalker interface {
	Interface(reflect.Value) error
}

InterfaceWalker implementations are able to handle interface values as they are encountered during the walk.

type Location

type Location uint
const (
	None Location = iota
	Map
	MapKey
	MapValue
	Slice
	SliceElem
	Array
	ArrayElem
	Struct
	StructField
	WalkLoc
)

func (Location) String

func (i Location) String() string

type PointerValueWalker

type PointerValueWalker interface {
	Pointer(reflect.Value) error
}

PointerValueWalker implementations are notified with the value of a particular pointer when a pointer is walked. Pointer is called right before PointerEnter.

type SliceWalker

type SliceWalker interface {
	Slice(reflect.Value) error
	SliceElem(int, reflect.Value) error
}

SliceWalker implementations are able to handle slice elements found within complex structures.

type StructWalker

type StructWalker interface {
	Struct(reflect.Value) error
	StructField(reflect.StructField, reflect.Value) error
}

StructWalker is an interface that has methods that are called for structs when a Walk is done.

Jump to

Keyboard shortcuts

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