...

Text file src/cuelang.org/go/doc/tutorial/basics/0_intro/40_constraints.txtar

Documentation: cuelang.org/go/doc/tutorial/basics/0_intro

     1exec cue eval check.cue
     2cmp stdout expect-stdout-cue
     3
     4-- frontmatter.toml --
     5title = "Constraints"
     6description = ""
     7
     8-- text.md --
     9Constraints specify what values are allowed.
    10To CUE they are just values like anything else,
    11but conceptually they can be explained as something in between types and
    12concrete values.
    13
    14But constraints can also reduce boilerplate.
    15If a constraint defines a concrete value, there is no need
    16to specify it in values to which this constraint applies.
    17
    18-- check.cue --
    19schema: {
    20    name:  string
    21    age:   int
    22    human: true // always true
    23}
    24
    25viola: schema
    26viola: {
    27    name: "Viola"
    28    age:  38
    29}
    30
    31-- expect-stdout-cue --
    32schema: {
    33    name:  string
    34    age:   int
    35    human: true
    36}
    37viola: {
    38    name:  "Viola"
    39    age:   38
    40    human: true
    41}

View as plain text