Documentation ¶
Overview ¶
Package types provides wrappers for Starlark types that can be unpacked by the Unpack helper functions to interpret call arguments.
Index ¶
- Variables
- type EitherOrNone
- func (e *EitherOrNone[A, B]) IsNone() bool
- func (e *EitherOrNone[A, B]) IsTypeA() bool
- func (e *EitherOrNone[A, B]) IsTypeB() bool
- func (e *EitherOrNone[A, B]) Type() string
- func (e *EitherOrNone[A, B]) Unpack(v starlark.Value) error
- func (e *EitherOrNone[A, B]) Value() starlark.Value
- func (e *EitherOrNone[A, B]) ValueA() (A, bool)
- func (e *EitherOrNone[A, B]) ValueB() (B, bool)
- type FloatOrInt
- type Nullable
- type NullableBool
- type NullableBytes
- type NullableCallable
- type NullableDict
- type NullableFloat
- type NullableInt
- type NullableIterable
- type NullableList
- type NullableSet
- type NullableString
- type NullableStringOrBytes
- func (p *NullableStringOrBytes) GoBytes() []byte
- func (p *NullableStringOrBytes) GoString() string
- func (p *NullableStringOrBytes) IsNull() bool
- func (p *NullableStringOrBytes) IsNullOrEmpty() bool
- func (p *NullableStringOrBytes) StarlarkBytes() starlark.Bytes
- func (p *NullableStringOrBytes) StarlarkString() starlark.String
- func (p *NullableStringOrBytes) Unpack(v starlark.Value) error
- type NullableTuple
- type NumericValue
- type OneOrMany
- type StringOrBytes
Constants ¶
This section is empty.
Variables ¶
var ( // NewNullableInt creates and returns a new NullableInt with the given default value. NewNullableInt = func(dv starlark.Int) *NullableInt { return NewNullable[starlark.Int](dv) } // NewNullableFloat creates and returns a new NullableFloat with the given default value. NewNullableFloat = func(dv starlark.Float) *NullableFloat { return NewNullable[starlark.Float](dv) } // NewNullableBool creates and returns a new NullableBool with the given default value. NewNullableBool = func(dv starlark.Bool) *NullableBool { return NewNullable[starlark.Bool](dv) } // NewNullableString creates and returns a new NullableString with the given default value. NewNullableString = func(dv starlark.String) *NullableString { return NewNullable[starlark.String](dv) } // NewNullableBytes creates and returns a new NullableBytes with the given default value. NewNullableBytes = func(dv starlark.Bytes) *NullableBytes { return NewNullable[starlark.Bytes](dv) } // NewNullableList creates and returns a new NullableList with the given default value. NewNullableList = func(dv *starlark.List) *NullableList { return NewNullable[*starlark.List](dv) } // NewNullableTuple creates and returns a new NullableTuple with the given default value. NewNullableTuple = func(dv starlark.Tuple) *NullableTuple { return NewNullable[starlark.Tuple](dv) } // NewNullableSet creates and returns a new NullableSet with the given default value. NewNullableSet = func(dv *starlark.Set) *NullableSet { return NewNullable[*starlark.Set](dv) } // NewNullableDict creates and returns a new NullableDict with the given default value. NewNullableDict = func(dv *starlark.Dict) *NullableDict { return NewNullable[*starlark.Dict](dv) } // NewNullableIterable creates and returns a new NullableIterable with the given default value. NewNullableIterable = func(dv starlark.Iterable) *NullableIterable { return NewNullable[starlark.Iterable](dv) } // NewNullableCallable creates and returns a new NullableCallable with the given default value. NewNullableCallable = func(dv starlark.Callable) *NullableCallable { return NewNullable[starlark.Callable](dv) } )
Functions ¶
This section is empty.
Types ¶
type EitherOrNone ¶ added in v0.1.2
type EitherOrNone[A starlark.Value, B starlark.Value] struct { // contains filtered or unexported fields }
EitherOrNone is an Unpacker that converts a Starlark None, A, or B to Go's starlark.Value.
func NewEitherOrNone ¶ added in v0.1.2
func NewEitherOrNone[A starlark.Value, B starlark.Value]() *EitherOrNone[A, B]
NewEitherOrNone creates and returns a new EitherOrNone.
func (*EitherOrNone[A, B]) IsNone ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) IsNone() bool
IsNone returns true if the value is None.
func (*EitherOrNone[A, B]) IsTypeA ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) IsTypeA() bool
IsTypeA returns true if the value is of type A.
func (*EitherOrNone[A, B]) IsTypeB ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) IsTypeB() bool
IsTypeB returns true if the value is of type B.
func (*EitherOrNone[A, B]) Type ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) Type() string
Type returns the type of the underlying value.
func (*EitherOrNone[A, B]) Unpack ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) Unpack(v starlark.Value) error
Unpack implements the starlark.Unpacker interface.
func (*EitherOrNone[A, B]) Value ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) Value() starlark.Value
Value returns the underlying value. You can use IsTypeA and IsTypeB to check which type it is.
func (*EitherOrNone[A, B]) ValueA ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) ValueA() (A, bool)
ValueA returns the value of type A, if available, and a boolean indicating its presence.
func (*EitherOrNone[A, B]) ValueB ¶ added in v0.1.2
func (e *EitherOrNone[A, B]) ValueB() (B, bool)
ValueB returns the value of type B, if available, and a boolean indicating its presence.
type FloatOrInt ¶
type FloatOrInt float64
FloatOrInt is an Unpacker that converts a Starlark int or float to Go's float64. There is no constructor for this type because it is a simple type alias of float64.
func (FloatOrInt) GoFloat ¶
func (p FloatOrInt) GoFloat() float64
GoFloat returns the Go float64 representation of the FloatOrInt.
func (FloatOrInt) GoFloat32 ¶ added in v0.1.2
func (p FloatOrInt) GoFloat32() float32
GoFloat32 returns the Go float32 representation of the FloatOrInt.
func (FloatOrInt) GoFloat64 ¶ added in v0.1.2
func (p FloatOrInt) GoFloat64() float64
GoFloat64 returns the Go float64 representation of the FloatOrInt.
func (FloatOrInt) GoInt ¶
func (p FloatOrInt) GoInt() int
GoInt returns the Go int representation of the FloatOrInt.
func (FloatOrInt) GoInt32 ¶ added in v0.1.2
func (p FloatOrInt) GoInt32() int32
GoInt32 returns the Go int32 representation of the FloatOrInt.
func (FloatOrInt) GoInt64 ¶ added in v0.1.2
func (p FloatOrInt) GoInt64() int64
GoInt64 returns the Go int64 representation of the FloatOrInt.
type Nullable ¶
Nullable is an Unpacker that converts a Starlark None or T to Go's starlark.Value.
func NewNullable ¶
NewNullable creates and returns a new Nullable with the given default value.
type NullableBool ¶
NullableBool is an Unpacker that converts a Starlark None or Bool.
type NullableBytes ¶
NullableBytes is an Unpacker that converts a Starlark None or Bytes.
type NullableCallable ¶
NullableCallable is an Unpacker that converts a Starlark None or Callable.
type NullableDict ¶
NullableDict is an Unpacker that converts a Starlark None or Dict.
type NullableFloat ¶
NullableFloat is an Unpacker that converts a Starlark None or Float.
type NullableInt ¶
NullableInt is an Unpacker that converts a Starlark None or Int.
type NullableIterable ¶
NullableIterable is an Unpacker that converts a Starlark None or Iterable.
type NullableList ¶
NullableList is an Unpacker that converts a Starlark None or List.
type NullableSet ¶
NullableSet is an Unpacker that converts a Starlark None or Set.
type NullableString ¶
NullableString is an Unpacker that converts a Starlark None or String.
type NullableStringOrBytes ¶
type NullableStringOrBytes struct {
// contains filtered or unexported fields
}
NullableStringOrBytes is an Unpacker that converts a Starlark None or string to Go's string.
func NewNullableStringOrBytes ¶
func NewNullableStringOrBytes(s string) *NullableStringOrBytes
NewNullableStringOrBytes creates and returns a new NullableStringOrBytes.
func NewNullableStringOrBytesNoDefault ¶ added in v0.1.2
func NewNullableStringOrBytesNoDefault() *NullableStringOrBytes
NewNullableStringOrBytesNoDefault creates and returns a new NullableStringOrBytes without a default value.
func (*NullableStringOrBytes) GoBytes ¶ added in v0.1.2
func (p *NullableStringOrBytes) GoBytes() []byte
GoBytes returns the Go byte slice representation of the NullableStringOrBytes, if the underlying value is nil, it returns nil.
func (*NullableStringOrBytes) GoString ¶
func (p *NullableStringOrBytes) GoString() string
GoString returns the Go string representation of the NullableStringOrBytes, if the underlying value is nil, it returns an empty string.
func (*NullableStringOrBytes) IsNull ¶
func (p *NullableStringOrBytes) IsNull() bool
IsNull returns true if the underlying value is nil.
func (*NullableStringOrBytes) IsNullOrEmpty ¶
func (p *NullableStringOrBytes) IsNullOrEmpty() bool
IsNullOrEmpty returns true if the underlying value is nil or an empty string.
func (*NullableStringOrBytes) StarlarkBytes ¶ added in v0.1.2
func (p *NullableStringOrBytes) StarlarkBytes() starlark.Bytes
StarlarkBytes returns the Starlark bytes representation of the NullableStringOrBytes, if the underlying value is nil, it returns a Starlark bytes with an empty string.
func (*NullableStringOrBytes) StarlarkString ¶ added in v0.1.2
func (p *NullableStringOrBytes) StarlarkString() starlark.String
StarlarkString returns the Starlark string representation of the NullableStringOrBytes, if the underlying value is nil, it returns a Starlark string with an empty string.
type NullableTuple ¶
NullableTuple is an Unpacker that converts a Starlark None or Tuple.
type NumericValue ¶
type NumericValue struct {
// contains filtered or unexported fields
}
NumericValue holds a Starlark numeric value and tracks its type. It can represent an integer or a float, and it prefers integers over floats.
func NewNumericValue ¶
func NewNumericValue() *NumericValue
NewNumericValue creates and returns a new NumericValue.
func (*NumericValue) Add ¶
func (n *NumericValue) Add(v starlark.Value) error
Add takes a Starlark Value and adds it to the NumericValue. It returns an error if the given value is neither an int nor a float.
func (*NumericValue) AsFloat ¶
func (n *NumericValue) AsFloat() float64
AsFloat returns the float representation of the NumericValue.
func (*NumericValue) Unpack ¶
func (n *NumericValue) Unpack(v starlark.Value) error
Unpack implements Unpacker.
func (*NumericValue) Value ¶
func (n *NumericValue) Value() starlark.Value
Value returns the Starlark Value representation of the NumericValue.
type OneOrMany ¶ added in v0.1.2
OneOrMany is a struct that can hold either a single value or multiple values of a specific type, and can be unpacked from a Starlark value.
func NewOneOrMany ¶ added in v0.1.2
NewOneOrMany creates and returns a new OneOrMany with the given default value.
func NewOneOrManyNoDefault ¶ added in v0.1.2
NewOneOrManyNoDefault creates and returns a new OneOrMany without a default value.
func (*OneOrMany[T]) First ¶ added in v0.1.2
func (o *OneOrMany[T]) First() T
First returns the first element in the slice, or the default value if the slice is nil or empty and a default is set. It returns the zero value of the type if the underlying slice is nil and has no default value.
func (*OneOrMany[T]) IsNull ¶ added in v0.1.2
IsNull checks if the struct is nil or has no underlying slice. It returns true if the struct is nil or has no underlying slice, no matter if a default value is set.
func (*OneOrMany[T]) Len ¶ added in v0.1.2
Len returns the length of the underlying slice or default value.
type StringOrBytes ¶
type StringOrBytes string
StringOrBytes is an Unpacker that converts a Starlark string or bytes to Go's string. It works because Go Starlark strings and bytes are both represented as Go strings. There is no constructor for this type because it is a simple type alias of string.
func (StringOrBytes) GoBytes ¶
func (p StringOrBytes) GoBytes() []byte
GoBytes returns the Go byte slice representation of the StringOrBytes.
func (StringOrBytes) GoString ¶
func (p StringOrBytes) GoString() string
GoString returns the Go string representation of the StringOrBytes.
func (StringOrBytes) IsEmpty ¶ added in v0.1.2
func (p StringOrBytes) IsEmpty() bool
IsEmpty returns true if the underlying value is an empty string.
func (StringOrBytes) StarlarkBytes ¶ added in v0.1.2
func (p StringOrBytes) StarlarkBytes() starlark.Bytes
StarlarkBytes returns the Starlark bytes representation of the StringOrBytes.
func (StringOrBytes) StarlarkString ¶
func (p StringOrBytes) StarlarkString() starlark.String
StarlarkString returns the Starlark string representation of the StringOrBytes.