Documentation
¶
Index ¶
- func Bind[T any](thread *starlark.Thread, dst *T, unpacker UnpackerInto[T]) starlark.Unpacker
- type AttrUnpacker
- type Canonicalizer
- type UnpackerInto
- func Attrs[T any](nestedUnpackersCreator func(thread *starlark.Thread, dst *T) []AttrUnpacker) UnpackerInto[T]
- func Canonicalize(base Canonicalizer) UnpackerInto[starlark.Value]
- func Decay[T any](base UnpackerInto[T]) UnpackerInto[any]
- func Dict[TKey comparable, TValue any](keyUnpacker UnpackerInto[TKey], valueUnpacker UnpackerInto[TValue]) UnpackerInto[map[TKey]TValue]
- func IfNonEmptyString[T any](base UnpackerInto[T]) UnpackerInto[T]
- func IfNotNone[T any](base UnpackerInto[T]) UnpackerInto[T]
- func Int[T constraints.Integer]() UnpackerInto[T]
- func List[T any](base UnpackerInto[T]) UnpackerInto[[]T]
- func Or[T any](unpackers []UnpackerInto[T]) UnpackerInto[T]
- func PathParser(pathFormat path.Format) UnpackerInto[path.Parser]
- func Pointer[T any](base UnpackerInto[T]) UnpackerInto[*T]
- func Singleton[T any](base UnpackerInto[T]) UnpackerInto[[]T]
- func Stringer[T fmt.Stringer](base UnpackerInto[T]) UnpackerInto[string]
- func Type[T starlark.Value](name string) UnpackerInto[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AttrUnpacker ¶
AttrUnpacker specifies how individual named attributes of a struct-like object need to be unpacked.
type Canonicalizer ¶
type Canonicalizer interface { Canonicalize(thread *starlark.Thread, v starlark.Value) (starlark.Value, error) GetConcatenationOperator() syntax.Token }
Canonicalizer of Starlark values. Whereas implementations of UnpackerInto provide an algorithm for converting Starlark values to native Go types, instances of Canonicalizer merely convert them to Starlark values that are considered canonical. For example, converting a string value provided to a rule attribute of type label to an instance of Label().
func IfNotNoneCanonicalizer ¶
func IfNotNoneCanonicalizer(base Canonicalizer) Canonicalizer
IfNotNoneCanonicalizer is a decorator for Canonicalizer that only calls into the underlying unpacker if the value is not None. This can be of use if None is used to denote that a value is unset.
type UnpackerInto ¶
type UnpackerInto[T any] interface { Canonicalizer UnpackInto(thread *starlark.Thread, v starlark.Value, dst *T) error }
UnpackerInto implements a strategy for unpacking a function argument of a Starlark function into a Go type.
var Any UnpackerInto[starlark.Value] = anyUnpackerInto{}
Any can unpack any Starlark value argument and store it into the provided value. This can be useful for situations where the actual parsing of an argument needs to be delayed to a later point in time (e.g., after interpreting other arguments that control the type of this argument.
var ApparentLabel UnpackerInto[label.ApparentLabel] = apparentLabelUnpackerInto{}
ApparentLabel is capable of unpacking string arguments that contain an apparent label (e.g., "@rules_go//go/platform:darwin_arm64").
If the label is not prefixed with a repo name (e.g., "//cmd/mytool") or relative (e.g., ":go_default_library"), the label is resolved to be relative to the package to which the current Starlark file belongs.
var ApparentRepo UnpackerInto[label.ApparentRepo] = apparentRepoUnpackerInto{}
ApparentRepo is capable of unpacking string arguments that contain an apparent repo (e.g., "rules_go"). It does not expect the repo name to have any leading "@" characters.
var ApparentTargetPattern UnpackerInto[label.ApparentTargetPattern] = apparentTargetPatternUnpackerInto{}
ApparentTargetPattern is capable of unpacking string arguments that contain an apparent target pattern (e.g., "@rules_swift//...").
If the target pattern is not prefixed with a repo name (e.g., "//...") or relative (e.g., ":all"), the target pattern is resolved to be relative to the package to which the current Starlark file belongs.
var Bool UnpackerInto[bool] = boolUnpackerInto{}
Bool is capable of unpacking boolean arguments.
var Module UnpackerInto[label.Module] = moduleUnpackerInto{}
Module is capable of unpacking a string value containing a Bazel module name (e.g., "rules_go").
var ModuleVersion UnpackerInto[label.ModuleVersion] = moduleVersionUnpackerInto{}
ModuleVersion is capable of unpacking a string containing a Bazel module version (e.g., "1.7.1", "0.0.0-20241220-5e258e33").
var StarlarkIdentifier UnpackerInto[label.StarlarkIdentifier] = starlarkIdentifierUnpackerInto{}
StarlarkIdentifier is capable of unpacking a string containing a Starlark identifier. Any string that is not a valid name for a Starlark identifier is rejected.
var String UnpackerInto[string] = stringUnpackerInto{}
String is capable of unpacking any Starlark string value into a native string.
var TargetName UnpackerInto[label.TargetName] = targetNameUnpackerInto{}
TargetName is capable of unpacking Starlark strings containing Bazel target names (e.g. "go_default_library"). Any string value that is not a valid Bazel target name is rejected.
var URL UnpackerInto[*url.URL] = urlUnpackerInto{}
URL is capable of unpacking Starlark strings containing URLs to a Go native URL.
func Attrs ¶
func Attrs[T any](nestedUnpackersCreator func(thread *starlark.Thread, dst *T) []AttrUnpacker) UnpackerInto[T]
Attrs can be used to unpack struct-like objects that have named attributes into native structs. Whenever unpacking is performed, a callback is invoked that is responsible for yielding new unpackers for each of the named attributes that is requested.
func Canonicalize ¶
func Canonicalize(base Canonicalizer) UnpackerInto[starlark.Value]
Canonicalize a Starlark value, as opposed to unpacking a value to a Go native type.
func Decay ¶
func Decay[T any](base UnpackerInto[T]) UnpackerInto[any]
Decay the unpacked value to one of type any. This is useful when used in combination with Or(), allowing unpacking to yield values that are otherwise incompatible with each other.
func Dict ¶
func Dict[TKey comparable, TValue any](keyUnpacker UnpackerInto[TKey], valueUnpacker UnpackerInto[TValue]) UnpackerInto[map[TKey]TValue]
Dict is capable of unpacking dicts declared in Starlark code to a Go native map.
func IfNonEmptyString ¶
func IfNonEmptyString[T any](base UnpackerInto[T]) UnpackerInto[T]
IfNonEmptyString is a decorator for UnpackerInto that only calls into the underlying unpacker if the value is a non-empty string. This can be of use if the default value of an argument is a string, and the empty string is used to denote that a value is unset.
func IfNotNone ¶
func IfNotNone[T any](base UnpackerInto[T]) UnpackerInto[T]
IfNotNone is a decorator for UnpackerInto that only calls into the underlying unpacker if the value is not None. This can be of use if None is used to denote that a value is unset.
func Int ¶
func Int[T constraints.Integer]() UnpackerInto[T]
Int is capable of unpacking Starlark integer values to a Go native integer type of choice.
func List ¶
func List[T any](base UnpackerInto[T]) UnpackerInto[[]T]
List is capable of unpacking a Starlark list value into a Go native slice.
func Or ¶
func Or[T any](unpackers []UnpackerInto[T]) UnpackerInto[T]
Or performs unpacking of a value by calling into a series of unpackers. This can be useful if an argument of a Starlark function permits values of multiple types (e.g., either a scalar value or a list).
This unpacker can be used in combination with the Decay() function to accept multiple types that are incompatible at the Go type level.
func PathParser ¶
func PathParser(pathFormat path.Format) UnpackerInto[path.Parser]
PathParser is capable of parsing pathname strings, wrapping them in a path parser for traversing over its components.
func Pointer ¶
func Pointer[T any](base UnpackerInto[T]) UnpackerInto[*T]
Pointer is a decorator for an UnpackerInto that assumes that the destination for unpacking is a pointer type. Upon successful unpacking, the pointer is assigned to allocated memory holding the unpacked value.
func Singleton ¶
func Singleton[T any](base UnpackerInto[T]) UnpackerInto[[]T]
Singleton is capable of unpacking a value and placing it in a slice containing a single element. This unpacker is typically used in combination with Or() in functions having arguments that can either be scalar or a list (e.g., for backward compatibility).
func Stringer ¶
func Stringer[T fmt.Stringer](base UnpackerInto[T]) UnpackerInto[string]
Stringer calls String() on the unpacked value and preserves that instead. This is useful if labels, URLs, etc. need to be captured in string form only.
Source Files
¶
- any.go
- apparent_label.go
- apparent_repo.go
- apparent_target_pattern.go
- attrs.go
- bind.go
- bool.go
- canonicalize.go
- decay.go
- dict.go
- if_non_empty_string.go
- if_not_none.go
- int.go
- list.go
- module.go
- module_version.go
- or.go
- path_parser.go
- pointer.go
- singleton.go
- starlark_identifier.go
- string.go
- stringer.go
- target_name.go
- type.go
- url.go