trim

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Package trim removes fields that may be inferred from another mixed in value that "dominates" it. For instance, a value that is merged in from a definition is considered to dominate a value from a regular struct that mixes in this definition. Values derived from constraints and comprehensions can also dominate other fields.

A value A is considered to be implied by a value B if A subsumes the default value of B. For instance, if a definition defines a field `a: *1 | int` and mixed in with a struct that defines a field `a: 1 | 2`, then the latter can be removed because a definition field dominates a regular field and because the latter subsumes the default value of the former.

Examples:

light: [string]: {
	room:          string
	brightnessOff: *0.0 | >=0 & <=100.0
	brightnessOn:  *100.0 | >=0 & <=100.0
}

light: ceiling50: {
	room:          "MasterBedroom"
	brightnessOff: 0.0    // this line
	brightnessOn:  100.0  // and this line will be removed
}

Results in:

// Unmodified: light: [string]: { ... }

light: ceiling50: {
	room: "MasterBedroom"
}

Index

Constants

This section is empty.

Variables

View Source
var Debug bool = false

Functions

func Files

func Files(files []*ast.File, inst cue.InstanceOrValue, cfg *Config) error

Files trims fields in the given files that can be implied from other fields, as can be derived from the evaluated values in inst. Trimming is done on a best-effort basis and only when the removed field is clearly implied by another field, rather than equal sibling fields.

Types

type Config

type Config struct {
	Trace bool
}

Config configures trim options.

Jump to

Keyboard shortcuts

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