Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lookup ¶
Lookup retrieves the value associated with the given key and stores it into the pointer that vptr points to.
Reports whether a value was found.
d = data.WithValue(d, x, 42) var out int data.Lookup(k, x, &out) // == true
Panics if the type of the value for the pointer is not compatible with the value associated with the key.
Types ¶
type Data ¶
type Data interface { // Keys returns all known keys for this Data object in an unspecified // order. Keys() []any // Values retrives the value associated with the given key or nil. Value(k any) any }
Data stores arbitrary data for Matchers and Replacers as they traverse or build the Go AST.
Data provides an interface very similar to context.Context.
func Index ¶
Index returns a copy of the provided Data object where items are indexed for fast lookup.
Lookups with Value or the Lookup function are constant time in the returned data object.
Use this if your workload is divided between write-heavy and read-heavy portions.
func WithValue ¶
WithValue returns a new Data with the given key-value pair associated with it.
d = data.WithValue(d, x, 42) d.Value(x) // == 42
The original object is left unmodified so if the returned Data object is discarded, its value will not be made available.
Retreiving the value from this Data object is a linear time operation. To optimize for read-heavy use cases, use the Index function.
Panics if either the key or the value are nil.