types

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 5 Imported by: 92

Documentation

Overview

Package types declares data types for Rego values and helper functions to operate on these types.

Index

Constants

This section is empty.

Variables

View Source
var A = NewAny()

A represents the superset of all types.

B represents an instance of the boolean type.

N represents an instance of the number type.

S represents an instance of the string type.

Functions

func Arity added in v0.34.0

func Arity(x Type) int

Arity returns the number of arguments in the function signature or zero if x is not a function. If the type is unknown, this function returns -1.

func Compare

func Compare(a, b Type) int

Compare returns -1, 0, 1 based on comparison between a and b.

func Contains added in v0.5.7

func Contains(a, b Type) bool

Contains returns true if a is a superset or equal to b.

func Nil

func Nil(a Type) bool

Nil returns true if a's type is unknown.

func Sprint

func Sprint(x Type) string

Sprint returns the string representation of the type.

func Void added in v0.34.0

func Void(x Type) bool

Void returns true if the function has no return value. This function returns false if x is not a function.

Types

type Any

type Any []Type

Any represents a dynamic type.

func NewAny

func NewAny(of ...Type) Any

NewAny returns a new Any type.

func (Any) Contains

func (t Any) Contains(other Type) bool

Contains returns true if t is a superset of other.

func (Any) MarshalJSON added in v0.5.7

func (t Any) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Any) Merge

func (t Any) Merge(other Type) Any

Merge return a new Any type that is the superset of t and other.

func (Any) String

func (t Any) String() string

func (Any) Union

func (t Any) Union(other Any) Any

Union returns a new Any type that is the union of the two Any types.

type Array

type Array struct {
	// contains filtered or unexported fields
}

Array represents the array type.

func NewArray

func NewArray(static []Type, dynamic Type) *Array

NewArray returns a new Array type.

func (*Array) Dynamic

func (t *Array) Dynamic() Type

Dynamic returns the type of the array's dynamic elements.

func (*Array) Len

func (t *Array) Len() int

Len returns the number of static array elements.

func (*Array) MarshalJSON added in v0.5.7

func (t *Array) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Array) Select

func (t *Array) Select(pos int) Type

Select returns the type of element at the zero-based pos.

func (*Array) String

func (t *Array) String() string

type Boolean

type Boolean struct{}

Boolean represents the boolean type.

func NewBoolean

func NewBoolean() Boolean

NewBoolean returns a new Boolean type.

func (Boolean) MarshalJSON added in v0.5.7

func (t Boolean) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Boolean) String

func (t Boolean) String() string

type DynamicProperty added in v0.5.7

type DynamicProperty struct {
	Key   Type
	Value Type
}

DynamicProperty represents a dynamic object property.

func NewDynamicProperty added in v0.5.7

func NewDynamicProperty(key, value Type) *DynamicProperty

NewDynamicProperty returns a new DynamicProperty object.

func (*DynamicProperty) MarshalJSON added in v0.5.7

func (p *DynamicProperty) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of p.

func (*DynamicProperty) String added in v0.5.7

func (p *DynamicProperty) String() string

type FuncArgs added in v0.33.0

type FuncArgs struct {
	Args     []Type `json:"args,omitempty"`
	Variadic Type   `json:"variadic,omitempty"`
}

FuncArgs represents the arguments that can be passed to a function.

func (FuncArgs) Arg added in v0.33.0

func (a FuncArgs) Arg(x int) Type

Arg returns the nth argument's type.

func (FuncArgs) String added in v0.33.0

func (a FuncArgs) String() string

type Function added in v0.5.9

type Function struct {
	// contains filtered or unexported fields
}

Function represents a function type.

func NewFunction added in v0.5.9

func NewFunction(args []Type, result Type) *Function

NewFunction returns a new Function object of the given argument and result types.

func NewVariadicFunction added in v0.33.0

func NewVariadicFunction(args []Type, varargs Type, result Type) *Function

NewVariadicFunction returns a new Function object. This function sets the variadic bit on the signature. Non-void variadic functions are not currently supported.

func (*Function) Args added in v0.5.9

func (t *Function) Args() []Type

Args returns the function's arguments as a slice, ignoring variadic arguments. Deprecated: Use FuncArgs instead.

func (*Function) FuncArgs added in v0.33.0

func (t *Function) FuncArgs() FuncArgs

FuncArgs returns the function's arguments.

func (*Function) MarshalJSON added in v0.5.9

func (t *Function) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Function) NamedFuncArgs added in v0.41.0

func (t *Function) NamedFuncArgs() FuncArgs

NamedFuncArgs returns the function's arguments, with a name and description if available.

func (*Function) NamedResult added in v0.41.0

func (t *Function) NamedResult() Type

Result returns the function's result type, without stripping name and description.

func (*Function) Result added in v0.5.9

func (t *Function) Result() Type

Result returns the function's result type.

func (*Function) String added in v0.5.9

func (t *Function) String() string

func (*Function) Union added in v0.5.9

func (t *Function) Union(other *Function) *Function

Union returns a new function representing the union of t and other. Functions must have the same arity to be unioned.

func (*Function) UnmarshalJSON added in v0.23.0

func (t *Function) UnmarshalJSON(bs []byte) error

UnmarshalJSON decodes the JSON serialized function declaration.

type NamedType added in v0.41.0

type NamedType struct {
	Name, Descr string
	Type        Type
}

func Named added in v0.41.0

func Named(name string, t Type) *NamedType

func (*NamedType) Description added in v0.41.0

func (n *NamedType) Description(d string) *NamedType

func (*NamedType) MarshalJSON added in v0.41.0

func (n *NamedType) MarshalJSON() ([]byte, error)

func (*NamedType) String added in v0.41.0

func (n *NamedType) String() string

type Null

type Null struct{}

Null represents the null type.

func NewNull

func NewNull() Null

NewNull returns a new Null type.

func (Null) MarshalJSON added in v0.5.7

func (t Null) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Null) String

func (t Null) String() string

type Number

type Number struct{}

Number represents the number type.

func NewNumber

func NewNumber() Number

NewNumber returns a new Number type.

func (Number) MarshalJSON added in v0.5.7

func (t Number) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Number) String

func (Number) String() string

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object represents the object type.

func NewObject

func NewObject(static []*StaticProperty, dynamic *DynamicProperty) *Object

NewObject returns a new Object type.

func (*Object) DynamicProperties added in v0.28.0

func (t *Object) DynamicProperties() *DynamicProperty

DynamicProperties returns the type of the object's dynamic elements.

func (*Object) DynamicValue added in v0.5.7

func (t *Object) DynamicValue() Type

DynamicValue returns the type of the object's dynamic elements.

func (*Object) Keys

func (t *Object) Keys() []interface{}

Keys returns the keys of the object's static elements.

func (*Object) MarshalJSON added in v0.5.7

func (t *Object) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Object) Select

func (t *Object) Select(name interface{}) Type

Select returns the type of the named property.

func (*Object) StaticProperties added in v0.28.0

func (t *Object) StaticProperties() []*StaticProperty

StaticProperties returns the type of the object's static elements.

func (*Object) String

func (t *Object) String() string

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set represents the set type.

func NewSet

func NewSet(of Type) *Set

NewSet returns a new Set type.

func (*Set) MarshalJSON added in v0.5.7

func (t *Set) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Set) String

func (t *Set) String() string

type StaticProperty added in v0.5.7

type StaticProperty struct {
	Key   interface{}
	Value Type
}

StaticProperty represents a static object property.

func NewStaticProperty added in v0.5.7

func NewStaticProperty(key interface{}, value Type) *StaticProperty

NewStaticProperty returns a new StaticProperty object.

func (*StaticProperty) MarshalJSON added in v0.5.7

func (p *StaticProperty) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of p.

type String

type String struct{}

String represents the string type.

func NewString

func NewString() String

NewString returns a new String type.

func (String) MarshalJSON added in v0.5.7

func (t String) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (String) String

func (String) String() string

type Type

type Type interface {
	String() string

	json.Marshaler
	// contains filtered or unexported methods
}

Type represents a type of a term in the language.

func Args added in v0.5.11

func Args(x ...Type) []Type

Args returns an argument list.

func Keys

func Keys(a Type) Type

Keys returns the type of keys that can be enumerated for a. For arrays, the keys are always number types, for objects the keys are always string types, and for sets the keys are always the type of the set element.

func Or

func Or(a, b Type) Type

Or returns a type that represents the union of a and b. If one type is a superset of the other, the superset is returned unchanged.

func Select

func Select(a Type, x interface{}) Type

Select returns a property or item of a.

func TypeOf

func TypeOf(x interface{}) Type

TypeOf returns the type of the Golang native value.

func Unmarshal added in v0.23.0

func Unmarshal(bs []byte) (result Type, err error)

Unmarshal deserializes bs and returns the resulting type.

func Values

func Values(a Type) Type

Values returns the type of values that can be enumerated for a.

Jump to

Keyboard shortcuts

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