types

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 2 Imported by: 15

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 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) GoInt

func (p FloatOrInt) GoInt() int

GoInt returns the Go int 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 (*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) 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(value 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 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) 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