types

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 4 Imported by: 7

Documentation

Overview

Package types provides wrappers for Starlark types that can be unpacked by the Unpack helper functions to interpret call arguments.

Index

Constants

This section is empty.

Variables

View Source
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.

func (*FloatOrInt) Unpack

func (p *FloatOrInt) Unpack(v starlark.Value) error

Unpack implements Unpacker.

type Nullable

type Nullable[T starlark.Value] struct {
	// contains filtered or unexported fields
}

Nullable is an Unpacker that converts a Starlark None or T to Go's starlark.Value.

func NewNullable

func NewNullable[T starlark.Value](defaultValue T) *Nullable[T]

NewNullable creates and returns a new Nullable with the given default value.

func (*Nullable[T]) IsNull

func (p *Nullable[T]) IsNull() bool

IsNull returns true if the underlying value is nil.

func (*Nullable[T]) Unpack

func (p *Nullable[T]) Unpack(v starlark.Value) error

Unpack implements Unpacker.

func (*Nullable[T]) Value

func (p *Nullable[T]) Value() T

Value returns the underlying value or default value if the underlying value is nil.

type NullableBool

type NullableBool = Nullable[starlark.Bool]

NullableBool is an Unpacker that converts a Starlark None or Bool.

type NullableBytes

type NullableBytes = Nullable[starlark.Bytes]

NullableBytes is an Unpacker that converts a Starlark None or Bytes.

type NullableCallable

type NullableCallable = Nullable[starlark.Callable]

NullableCallable is an Unpacker that converts a Starlark None or Callable.

type NullableDict

type NullableDict = Nullable[*starlark.Dict]

NullableDict is an Unpacker that converts a Starlark None or Dict.

type NullableFloat

type NullableFloat = Nullable[starlark.Float]

NullableFloat is an Unpacker that converts a Starlark None or Float.

type NullableInt

type NullableInt = Nullable[starlark.Int]

NullableInt is an Unpacker that converts a Starlark None or Int.

type NullableIterable

type NullableIterable = Nullable[starlark.Iterable]

NullableIterable is an Unpacker that converts a Starlark None or Iterable.

type NullableList

type NullableList = Nullable[*starlark.List]

NullableList is an Unpacker that converts a Starlark None or List.

type NullableSet

type NullableSet = Nullable[*starlark.Set]

NullableSet is an Unpacker that converts a Starlark None or Set.

type NullableString

type NullableString = Nullable[starlark.String]

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.

func (*NullableStringOrBytes) Unpack

Unpack implements Unpacker.

type NullableTuple

type NullableTuple = Nullable[starlark.Tuple]

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

type OneOrMany[T starlark.Value] struct {
	// contains filtered or unexported fields
}

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

func NewOneOrMany[T starlark.Value](defaultValue T) *OneOrMany[T]

NewOneOrMany creates and returns a new OneOrMany with the given default value.

func NewOneOrManyNoDefault added in v0.1.2

func NewOneOrManyNoDefault[T starlark.Value]() *OneOrMany[T]

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

func (o *OneOrMany[T]) IsNull() bool

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

func (o *OneOrMany[T]) Len() int

Len returns the length of the underlying slice or default value.

func (*OneOrMany[T]) Slice added in v0.1.2

func (o *OneOrMany[T]) Slice() []T

Slice returns the underlying slice, or a slice containing the default value if the slice is nil and a default is set. It returns an empty slice if the underlying slice is nil and has no default value.

func (*OneOrMany[T]) Unpack added in v0.1.2

func (o *OneOrMany[T]) Unpack(v starlark.Value) error

Unpack implements the starlark.Unpacker interface, allowing the struct to unpack from a starlark.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.

func (*StringOrBytes) Unpack

func (p *StringOrBytes) Unpack(v starlark.Value) error

Unpack implements Unpacker.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL