Skip to main content

Module schema

Module schema 

Source
Expand description

TC.1: ConfigSchema / ConfigValue — what an option’s value is shaped like, as data, plus schema-checked validation that reports a path. TC.1 — what an option’s value is shaped like, as data.

Design: typed-configuration.md.

Options have always been typed on the Rust side — Option<T> over an OptionType. What they have never been is typed to anything that is not Rust. The type-erased surface every runtime-name consumer goes through (:set, the TOML loader, plugin introspection, :describe-option) exposed a type_label(): &str and a formatted String, and a label plus a string is not enough to render a composite, validate a field, or write a value back to TOML.

ConfigSchema is that description and ConfigValue is a value shaped by it. Together they are what makes design §5.12’s :customize — “a type-aware editing buffer” — possible at all, and what lets a plugin declare a record without the host needing a Rust type for it (WIT has no generics; self-description is the expressible answer).

Additive by construction. parse / format keep their round-trip contract and remain the :set surface, because a command line is a text surface and typing a record into one is not an improvement. A scalar option behaves identically before and after this module existed — its schema is derived from what it already declares rather than written by hand.

Structs§

SchemaError
A validation failure, carrying where it happened.
SchemaField
One field of a ConfigSchema::Record.

Enums§

ConfigSchema
The declared shape of an option’s value.
ConfigValue
A value shaped by a ConfigSchema.
ScalarKind
The leaf kinds. Deliberately the three the ABI already carries plus nothing: a float would need a parse/format round-trip that survives every locale and every plugin language’s formatter, and no option in the workspace wants one. Adding it later is additive; guessing now is not.

Functions§

config_value_to_toml
A ConfigValue as TOML. The inverse of toml_to_config_value, used by ConfigValue’s format() — which is what :set foo? echoes and what :describe-option shows.
dot_path
Join a schema path onto an option name. A record field needs the separating dot (opt + target.file); an index does not (opt + [2]).
toml_to_config_value
TC.2 — a TOML value as a ConfigValue tree.
validate
Check value against schema, reporting the first failure with its path.