input-toml or input-yaml only.Expand description
Declared input: read a file, parse it, validate it once, and report every problem on its file and line.
Each format is its own feature. input-yaml parses YAML with
serde-saphyr, and input-toml parses TOML with the toml crate; neither
needs the other. validate adds Input::check and Input::load, which
validate with garde, and input is input-yaml with validate. This is
the one boundary where a CLI’s config enters. Downstream code keeps the
validated type and never checks it again.
A check that runs after the read, such as one that needs a file the config
names, places its problem with a FieldPath and Input::problem_at,
the way the loader places garde’s.
A text’s Format is chosen, never guessed. Input::open reads it from
the file’s extension, and Input::new_with_format takes it for text in
memory. With input-yaml, Input::new and Input::read are YAML.
use ctl_core::input::Input;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Config {
name: String,
}
let config: Config = Input::new("toy.yaml", "name: release\n").parse()?;
assert_eq!(config.name, "release");
let error = Input::new("toy.yaml", "name: a\nname: b\n")
.parse::<Config>()
.unwrap_err();
assert!(error.to_string().starts_with("toy.yaml"));Structs§
- Entry
- One entry of the top-level mapping or table of a text.
- Field
Path - The steps from a document’s root down to a field.
- Input
- A named text, ready to parse and validate.
- Input
Error - Why an input was refused: every problem found, each placed on a line when the text allows it.
- Limits
- Overrides for the limits a text is held to, one per field.
Noneleaves the field to the next tier. - Loosened
input-yaml - A limit a repository’s
REPO_FILEraises above its default. - Place
- The 1-based line and column where a field is written.
- Problem
- One thing wrong with an input.
- Tagged
input-yaml - A value and the YAML tag written on its node, such as
!overrideincode_span_size: !override 0:Tagged(0, Some("!override".into())). A node with no tag reads asTagged(value, None), and an untagged enum inside reads the plain value of a tagged node. Capture and emit the resolved YAML tag attached to a value.
Enums§
- Format
- How a text is written.
- Step
- One step down a
FieldPath: a mapping key or a sequence index. - Written
- How the value of an
Entryis written.
Constants§
- REPO_
FILE input-yaml - Where a repository overrides limits, relative to its root.
Functions§
- set_
default_ limits - Set the process-wide default, which a call’s
Input::limitsbeats, and withinput-yamla repository’s.ctl/input.yamltoo. - use_
repo_ limits input-yaml - Read
limits:fromroot’sREPO_FILEand install it for every later parse in this process. A repository without the file overrides nothing. The file itself is read under the process default, not under whatever repository was installed before.