Skip to main content

Module yaml

Module yaml 

Source
Expand description

A hand-rolled YAML subset reader for config files → serde_json::Value.

agentd’s config file may be YAML (--config agentd.yaml) — but the minimalism moat forbids a YAML crate (serde_yaml is also unmaintained), so, like the cron parser, the HTTP client, and the JSON-with-comments stripper, this is written on std alone and produces the same serde_json::Value tree the JSON path yields. One document model, two surface syntaxes; everything downstream (typed deserialization, schema validation, hot reload) is format-agnostic.

§What is supported (the config-file subset)

  • block mappings (key: value, nesting by indentation) and block sequences (- item, including - key: value items and nested sequences, and a sequence at the same indent as its key);
  • flow collections ([a, b], {k: v}), nested and spanning lines;
  • scalars: plain, single-quoted ('' escape), double-quoted (JSON escapes + \xHH/\uHHHH/\UHHHHHHHH), and block scalars | / > with -/+ chomping and an explicit indentation indicator;
  • multi-line plain scalars (continuation lines fold with a space);
  • comments (# at line start or after whitespace), blank lines, --- / ... document markers, % directives, a UTF-8 BOM, CRLF line endings;
  • YAML 1.2 core-schema typing of plain scalars: null/~/empty → null, true/false (any case) → bool, decimal/0x/0o integers, floats; everything else is a string (yes/no/on/off are STRINGS — the 1.1 footgun is deliberately absent).

§What is rejected, loudly

Anchors/aliases (&a/*a), tags (!!str), merge keys (<<), complex keys (? ), multiple documents, tab indentation, multi-line quoted scalars, and duplicate mapping keys — each is a parse error naming the line and column, never a silent guess. Non-finite floats (.inf/.nan) are rejected because JSON cannot carry them.

Structs§

YamlError
A YAML parse error with a 1-based line and column.

Functions§

parse
Parse one YAML document into a JSON value. An empty document is null.
parse_inline
Parse a single inline YAML value (a scalar or a flow collection) — the shape an env var or a --flag value carries: 12, true, [a, b], {k: v}, "quoted". A plain scalar that types as a string comes back verbatim (trimmed).