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) Arity() int
- 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) Merge(other Type) *Object
- 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 ¶
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 ¶
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 ¶
MarshalJSON returns the JSON encoding of t.
type Boolean ¶
type Boolean struct{}
Boolean represents the boolean type.
func (Boolean) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
type DynamicProperty ¶
DynamicProperty represents a dynamic object property.
func NewDynamicProperty ¶
func NewDynamicProperty(key, value Type) *DynamicProperty
NewDynamicProperty returns a new DynamicProperty object.
func (*DynamicProperty) MarshalJSON ¶
func (p *DynamicProperty) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of p.
func (*DynamicProperty) String ¶
func (p *DynamicProperty) String() string
type FuncArgs ¶
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 ¶
type Function struct {
// contains filtered or unexported fields
}
Function represents a function type.
func NewFunction ¶
NewFunction returns a new Function object of the given argument and result types.
func NewVariadicFunction ¶
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 ¶
Args returns the function's arguments as a slice, ignoring variadic arguments. Deprecated: Use FuncArgs instead.
func (*Function) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (*Function) NamedFuncArgs ¶
NamedFuncArgs returns the function's arguments, with a name and description if available.
func (*Function) NamedResult ¶
Result returns the function's result type, without stripping name and description.
func (*Function) Union ¶
Union returns a new function representing the union of t and other. Functions must have the same arity to be unioned.
func (*Function) UnmarshalJSON ¶
UnmarshalJSON decodes the JSON serialized function declaration.
type NamedType ¶
NamedType represents a type alias with an arbitrary name and description. This is useful for generating documentation for built-in functions.
func Named ¶
Named returns the passed type as a named type. Named types are only valid at the top level of built-in functions. Note that nested named types cause panic.
func (*NamedType) Description ¶
func (*NamedType) MarshalJSON ¶
type Null ¶
type Null struct{}
Null represents the null type.
func (Null) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
type Number ¶
type Number struct{}
Number represents the number type.
func (Number) MarshalJSON ¶
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 ¶
func (t *Object) DynamicProperties() *DynamicProperty
DynamicProperties returns the type of the object's dynamic elements.
func (*Object) DynamicValue ¶
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 ¶
MarshalJSON returns the JSON encoding of t.
func (*Object) StaticProperties ¶
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 ¶
MarshalJSON returns the JSON encoding of t.
type StaticProperty ¶
type StaticProperty struct { Key interface{} Value Type }
StaticProperty represents a static object property.
func NewStaticProperty ¶
func NewStaticProperty(key interface{}, value Type) *StaticProperty
NewStaticProperty returns a new StaticProperty object.
func (*StaticProperty) MarshalJSON ¶
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 ¶
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.