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 withkeywords,length,format,references, orunique. It does not combine withrange, which needs an integer or float field.#[confval(length = ...)]bounds the character count of a string.length_constraint!declares the bound withmax:alone or withmin:andmax:, plus an optionalhelp:.#[confval(format = ...)]parses a string as a named format.Ipv4,Ipv6,Ip, andAbsolutePathship with the crate. A domain format is a type that implements theFormattrait.#[confval(unique)]rejects a string list entry that repeats an earlier one, at the repeat's own span.
Added
#[confval(non_empty)]on aStringleaf or a string list. The derive runs the check during validation. The schema records it asSchemaField::non_empty, aboolflag separate from theConstraintslot. The LSP hover renders "Must not be empty." The prelude exportsNON_EMPTYandNonEmptyConstraintfor a handwritten spec.#[confval(length = PATH)]on aStringleaf, wherePATHnames alength_constraint!const. The derive runs the check during validation. The schema records it asConstraint::Lengthwith 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 exportsLengthConstraintandlength_constraint!.lengthis mutually exclusive withkeywords,range,format, andreferences.#[confval(format = PATH)]on aStringleaf or a string list, wherePATHnames a type that implementsFormat. The derive runscheck_formaton a leaf andcheck_each_formaton a list. The schema records the format's name and check asConstraint::Format. The LSP hover renders "Format: IPv4 address." The quick fix checks a default against the format. The prelude exportsFormat, the four built-in types,check_format, andcheck_each_format.formatis mutually exclusive withkeywords,range,length, andreferences.#[confval(unique)]on a string list. The derive runsUNIQUE.check_listduring validation and reportsduplicate value in {field}: "{value}"at each repeat, with a related label at the first occurrence. The schema records it asSchemaField::unique, aboolflag besidenon_empty. The LSP hover renders "Entries must be unique." The prelude exportsUNIQUEandUniqueConstraint.uniquecombines withkeywords,format,non_empty, anddefault, because the default list is empty and so unique. A duplicate check that spans blocks stays in theValidatebody.- The
textDocument/documentLinkhandler inconfval-lsp. ALocated<PathBuf>field renders as a clickable link in the editor. The link target resolves relative paths against the document's directory.
Changed
check_referencesnow 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"] }