Skip to main content

confval v0.10.0

New recorded constraints for the derive: non_empty, length, format, and unique.

Highlights

  • #[confval(non_empty)] rejects an empty or whitespace-only string. On a list it also rejects a list with zero elements. The flag is a precondition on the value, so a field can combine it with keywords, length, format, references, or unique. It does not combine with range, which needs an integer or float field.
  • #[confval(length = ...)] bounds the character count of a string. length_constraint! declares the bound with max: alone or with min: and max:, plus an optional help:.
  • #[confval(format = ...)] parses a string as a named format. Ipv4, Ipv6, Ip, and AbsolutePath ship with the crate. A domain format is a type that implements the Format trait.
  • #[confval(unique)] rejects a string list entry that repeats an earlier one, at the repeat's own span.

Added

  • #[confval(non_empty)] on a String leaf or a string list. The derive runs the check during validation. The schema records it as SchemaField::non_empty, a bool flag separate from the Constraint slot. The LSP hover renders "Must not be empty." The prelude exports NON_EMPTY and NonEmptyConstraint for a handwritten spec.
  • #[confval(length = PATH)] on a String leaf, where PATH names a length_constraint! const. The derive runs the check during validation. The schema records it as Constraint::Length with numeric bounds. The LSP hover renders "Between 1 and 63 characters." or "At most 253 characters." The quick fix checks a default against the bound. The prelude exports LengthConstraint and length_constraint!. length is mutually exclusive with keywords, range, format, and references.
  • #[confval(format = PATH)] on a String leaf or a string list, where PATH names a type that implements Format. The derive runs check_format on a leaf and check_each_format on a list. The schema records the format's name and check as Constraint::Format. The LSP hover renders "Format: IPv4 address." The quick fix checks a default against the format. The prelude exports Format, the four built-in types, check_format, and check_each_format. format is mutually exclusive with keywords, range, length, and references.
  • #[confval(unique)] on a string list. The derive runs UNIQUE.check_list during validation and reports duplicate value in {field}: "{value}" at each repeat, with a related label at the first occurrence. The schema records it as SchemaField::unique, a bool flag beside non_empty. The LSP hover renders "Entries must be unique." The prelude exports UNIQUE and UniqueConstraint. unique combines with keywords, format, non_empty, and default, because the default list is empty and so unique. A duplicate check that spans blocks stays in the Validate body.
  • The textDocument/documentLink handler in confval-lsp. A Located<PathBuf> field renders as a clickable link in the editor. The link target resolves relative paths against the document's directory.

Changed

  • check_references now runs in time linear to the size of the document. The pass collects the labels of each scope instance once and reuses them for every reference into that scope. Before this release, each reference collected the labels again, so a file with many references to many blocks slowed the editor.

Upgrading

No breaking changes from 0.9.0.

[dependencies]
confval = { version = "0.10", features = ["derive", "hcl", "color"] }