toml or 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. yaml parses YAML with serde-saphyr,
and toml parses TOML with the toml crate; neither needs the other.
validate adds Input::check and Input::load, which validate with
garde. This is the one boundary where a CLI’s config enters. Downstream
code keeps the validated type and never checks it again. With no format
feature the crate is empty.
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 yaml, Input::new and Input::read are YAML.
use ctl_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"));§Cargo features
yaml— Declared input from YAML: parse with serde-saphyr and place every problem on its file and line through yamled. Adds the YAML-onlyLimitsfields and the repository’s.ctl/input.yaml. Needs no garde withoutvalidate.toml— Declared input from TOML:Input::openreads.tomlfiles, and thetomlcrate’s span-carrying tree places each problem on its line and column. Needs no YAML crate, and no garde withoutvalidate.validate— Validate with garde:Input::checkandInput::load.
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
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
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 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 withyamla repository’s.ctl/input.yamltoo. - use_
repo_ limits 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.