Skip to main content

Module input

Module input 

Source
Available on crate features 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§

FieldPath
The steps from a document’s root down to a field.
Input
A named text, ready to parse and validate.
InputError
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. None leaves the field to the next tier.
Loosenedinput-yaml
A limit a repository’s REPO_FILE raises above its default.
Place
The 1-based line and column where a field is written.
Problem
One thing wrong with an input.

Enums§

Format
How a text is written.
Step
One step down a FieldPath: a mapping key or a sequence index.

Constants§

REPO_FILEinput-yaml
Where a repository overrides limits, relative to its root.

Functions§

set_default_limits
Set the process-wide default, which a call’s Input::limits beats, and with input-yaml a repository’s .ctl/input.yaml too.
use_repo_limitsinput-yaml
Read limits: from root’s REPO_FILE and 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.