Documentation
¶
Index ¶
- func Decode[T any](dec *Decoding, tr *Tree) (T, error)
- func DecodeInto(dec *Decoding, tr *Tree, into any) error
- func Transmute[T any](tr *Transmutation, from any) (T, error)
- func TransmuteInto(tr *Transmutation, from, to any) error
- type DecodeError
- type DecodeTarget
- type Decoder
- type Decoding
- type Encoding
- type Transmutation
- type Tree
- func (t *Tree) BreadthFirst() iter.Seq[*Tree]
- func (t *Tree) Child(name any) *Tree
- func (t *Tree) Children() iter.Seq[*Tree]
- func (t *Tree) DepthFirst() iter.Seq[*Tree]
- func (t *Tree) IsNil() bool
- func (t *Tree) IsPrimitive() bool
- func (t *Tree) IsStructField() bool
- func (t *Tree) Name() any
- func (t *Tree) NumChildren() uint
- func (t *Tree) Parent() *Tree
- func (t *Tree) Path() (path []any)
- func (t *Tree) SetValue(val reflect.Value)
- func (t *Tree) String() string
- func (t *Tree) StructField() reflect.StructField
- func (t *Tree) Value() reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transmute ¶
func Transmute[T any](tr *Transmutation, from any) (T, error)
Transmute encodes the given `from` value into a tree, and decodes the tree into a variable of type `T`.
func TransmuteInto ¶
func TransmuteInto(tr *Transmutation, from, to any) error
TransmuteInto encodes the given `from` value into a tree and decodes the tree directly into the given `to` value.
Types ¶
type DecodeError ¶
type DecodeError struct {
From *Tree
Into DecodeTarget
Err error
}
func (*DecodeError) PathString ¶
func (e *DecodeError) PathString() string
PathSTring returns a dot-separated string representation of the path.
func (*DecodeError) Unwrap ¶
func (e *DecodeError) Unwrap() error
Unwrap returns the underlying error.
type DecodeTarget ¶
func (DecodeTarget) IsPrimitive ¶
func (d DecodeTarget) IsPrimitive() bool
func (DecodeTarget) IsStructField ¶
func (d DecodeTarget) IsStructField() bool
func (DecodeTarget) StructField ¶
func (d DecodeTarget) StructField() reflect.StructField
type Decoder ¶
type Decoder func(tr *Tree, target DecodeTarget) error
type Decoding ¶
type Decoding struct {
StructTag string
// Decoder is a custom decoder. If nil is returned, the default decoding
// mechanism is used.
Decoder func(tr *Tree, target DecodeTarget) Decoder
Unmatched func(tr *Tree, target DecodeTarget) (*Tree, error)
}
type Transmutation ¶
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
func DecodeIgnoreUnmatched ¶
func DecodeIgnoreUnmatched(*Tree, DecodeTarget) (*Tree, error)
func (*Tree) BreadthFirst ¶
BreadthFirst returns a sequence of the tree nodes in breadth-first order.
func (*Tree) Children ¶
Children returns a sequence of the children of this node, preserving their order.
func (*Tree) DepthFirst ¶
DepthFirst returns a sequence of the tree nodes in depth-first order.
func (*Tree) IsPrimitive ¶
func (*Tree) IsStructField ¶
func (*Tree) Name ¶
Name returns the name of this node in the parent node. If this node is root or represents an embedded node (i.e. anonymous struct field), the name is nil.
func (*Tree) NumChildren ¶
NumChildren returns the number of children of this node.
func (*Tree) Parent ¶
Parent returns the parent of this node. If this is a root node, nil is returned.
func (*Tree) Path ¶
Path returns the path from the root to this node. The first element is the name of
func (*Tree) SetValue ¶
SetValue updates the value of this node to the given val. The original value is not further used.
func (*Tree) StructField ¶
func (t *Tree) StructField() reflect.StructField