Documentation ¶
Overview ¶
Package types declares data types for Rego values and helper functions to operate on these types.
Index ¶
- Variables
- func Arity(x Type) int
- func Compare(a, b Type) int
- func Contains(a, b Type) bool
- func Nil(a Type) bool
- func Sprint(x Type) string
- func Void(x Type) bool
- type Any
- type Array
- type Boolean
- type DynamicProperty
- type FuncArgs
- type Function
- func (t *Function) Args() []Type
- func (t *Function) FuncArgs() FuncArgs
- func (t *Function) MarshalJSON() ([]byte, error)
- func (t *Function) NamedFuncArgs() FuncArgs
- func (t *Function) NamedResult() Type
- func (t *Function) Result() Type
- func (t *Function) String() string
- func (t *Function) Union(other *Function) *Function
- func (t *Function) UnmarshalJSON(bs []byte) error
- type NamedType
- type Null
- type Number
- type Object
- func (t *Object) DynamicProperties() *DynamicProperty
- func (t *Object) DynamicValue() Type
- func (t *Object) Keys() []interface{}
- func (t *Object) MarshalJSON() ([]byte, error)
- func (t *Object) Select(name interface{}) Type
- func (t *Object) StaticProperties() []*StaticProperty
- func (t *Object) String() string
- type Set
- type StaticProperty
- type String
- type Type
Constants ¶
This section is empty.
Variables ¶
var A = NewAny()
A represents the superset of all types.
var B = NewBoolean()
B represents an instance of the boolean type.
var N = NewNumber()
N represents an instance of the number type.
var S = NewString()
S represents an instance of the string type.
Functions ¶
func Arity ¶ added in v0.34.0
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.
Types ¶
type Any ¶
type Any []Type
Any represents a dynamic type.
func (Any) MarshalJSON ¶ added in v0.5.7
MarshalJSON returns the JSON encoding of t.
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array represents the array type.
func (*Array) MarshalJSON ¶ added in v0.5.7
MarshalJSON returns the JSON encoding of t.
type Boolean ¶
type Boolean struct{}
Boolean represents the boolean type.
func (Boolean) MarshalJSON ¶ added in v0.5.7
MarshalJSON returns the JSON encoding of t.
type DynamicProperty ¶ added in v0.5.7
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.
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
NewFunction returns a new Function object of the given argument and result types.
func NewVariadicFunction ¶ added in v0.33.0
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
Args returns the function's arguments as a slice, ignoring variadic arguments. Deprecated: Use FuncArgs instead.
func (*Function) MarshalJSON ¶ added in v0.5.9
MarshalJSON returns the JSON encoding of t.
func (*Function) NamedFuncArgs ¶ added in v0.41.0
NamedFuncArgs returns the function's arguments, with a name and description if available.
func (*Function) NamedResult ¶ added in v0.41.0
Result returns the function's result type, without stripping name and description.
func (*Function) Union ¶ added in v0.5.9
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
UnmarshalJSON decodes the JSON serialized function declaration.
type NamedType ¶ added in v0.41.0
func (*NamedType) Description ¶ added in v0.41.0
func (*NamedType) MarshalJSON ¶ added in v0.41.0
type Null ¶
type Null struct{}
Null represents the null type.
func (Null) MarshalJSON ¶ added in v0.5.7
MarshalJSON returns the JSON encoding of t.
type Number ¶
type Number struct{}
Number represents the number type.
func (Number) MarshalJSON ¶ added in v0.5.7
MarshalJSON returns the JSON encoding of t.
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
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
MarshalJSON returns the JSON encoding of t.
func (*Object) StaticProperties ¶ added in v0.28.0
func (t *Object) StaticProperties() []*StaticProperty
StaticProperties returns the type of the object's static elements.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents the set type.
func (*Set) MarshalJSON ¶ added in v0.5.7
MarshalJSON returns the JSON encoding of t.
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 (String) MarshalJSON ¶ added in v0.5.7
MarshalJSON returns the JSON encoding of t.
type Type ¶
Type represents a type of a term in the language.
func Keys ¶
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 ¶
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.