reflect

CUE v0.19.0

Package reflect provides functions for inspecting CUE values beyond their data, such as the constraints that apply to a field whether or not it is present.

Functions

Allows

cue
Allows: func(s: _, label: _) -> bool

Allows reports whether the field or index label may ever appear on the struct or list s: an open struct admits any label, a closed struct admits its declared fields and labels matching its pattern constraints, and a closed list admits in-range indices. It is the structural counterpart to the exists builtin, and never errors where exists does: for an undeclared name on a closed struct, exists reports an error while Allows reports false. An index that no list can have, such as a negative one, is never allowed.

Allows is an ordinary function, so s is evaluated as any argument is. A disjunction resolves to its default first: for s: *#A | #B, Allows asks about #A. A disjunction without a default cannot be resolved, so the call stays incomplete, even when every disjunct would give the same answer.

Field

cue
Field: func(s: _, name: string) -> _

Field reports the value that the field name has, or would have, in the struct s. It is defined as the value of name in the unification s & {(name): _}.

For a present regular field this is its value. For a declared optional or required field it is the field's constraint, with any applicable pattern constraints unified in. For an undeclared field on an open struct it is the meet of the applicable pattern constraints, or _ when there are none. A field that can never exist — an undeclared name on a closed struct or definition — is an error.

Install CUE