package river12import "github.com/grafana/agent/pkg/river/internal/value"34// Our types in this file are re-implementations of interfaces from5// value.Capsule. They are *not* defined as type aliases, since pkg.go.dev6// would show the type alias instead of the contents of that type (which IMO is7// a frustrating user experience).8//9// The types below must be kept in sync with the internal package, and the10// checks below ensure they're compatible.11var (12_ value.Unmarshaler = (Unmarshaler)(nil)13_ value.Capsule = (Capsule)(nil)14_ value.ConvertibleFromCapsule = (ConvertibleFromCapsule)(nil)15_ value.ConvertibleIntoCapsule = (ConvertibleIntoCapsule)(nil)16)1718// The Unmarshaler interface allows a type to hook into River decoding and19// decode into another type or provide pre-decoding logic.20type Unmarshaler interface {21// UnmarshalRiver is invoked when decoding a River value into a Go value. f22// should be called with a pointer to a value to decode into. UnmarshalRiver23// will not be called on types which are squashed into the parent struct24// using `river:",squash"`.25UnmarshalRiver(f func(v interface{}) error) error26}2728// Capsule is an interface marker which tells River that a type should always29// be treated as a "capsule type" instead of the default type River would30// assign.31//32// Capsule types are useful for passing around arbitrary Go values in River33// expressions and for declaring new synthetic types with custom conversion34// rules.35//36// By default, only two capsule values of the same underlying Go type are37// compatible. Types which implement ConvertibleFromCapsule or38// ConvertibleToCapsule can provide custom logic for conversions from and to39// other types.40type Capsule interface {41// RiverCapsule marks the type as a Capsule. RiverCapsule is never invoked by42// River.43RiverCapsule()44}4546// ErrNoConversion is returned by implementations of ConvertibleFromCapsule and47// ConvertibleToCapsule when a conversion with a specific type is unavailable.48//49// Returning this error causes River to fall back to default conversion rules.50var ErrNoConversion = value.ErrNoConversion5152// ConvertibleFromCapsule is a Capsule which supports custom conversion from53// any Go type which is not the same as the capsule type.54type ConvertibleFromCapsule interface {55Capsule5657// ConvertFrom updates the ConvertibleFromCapsule value based on the value of58// src. src may be any Go value, not just other capsules.59//60// ConvertFrom should return ErrNoConversion if no conversion is available61// from src. Other errors are treated as a River decoding error.62ConvertFrom(src interface{}) error63}6465// ConvertibleIntoCapsule is a Capsule which supports custom conversion into66// any Go type which is not the same as the capsule type.67type ConvertibleIntoCapsule interface {68Capsule6970// ConvertInto should convert its value and store it into dst. dst will be a71// pointer to a Go value of any type.72//73// ConvertInto should return ErrNoConversion if no conversion into dst is74// available. Other errors are treated as a River decoding error.75ConvertInto(dst interface{}) error76}777879