Expand description
Load, merge and emit layered JSON and TOML configuration.
Three steps, each a function, and a caller composes them:
load_layersreads each path into aValue, keeping the format it was read as;mergefolds the flat layer list from left to right — any in-memory overlays are just more layers appended to the list;interpolate, if wanted, resolves${...}references once, on the merged document.
format::emit renders the result. JSON and TOML appear only in
format and value; the merge and interpolation never learn either
exists.
No flag names. An error from this crate carries key paths and file paths;
the command-line spelling that produced it is knf-cli’s to add. That is
what LoadError exists for — the failures that have an obvious
command-line remedy are typed, so the caller decides how to name them.
Re-exports§
pub use format::Format;pub use value::BadDatetime;pub use value::IntegerOutOfRange;pub use value::NonFiniteFloat;pub use value::NullInToml;pub use value::TomlError;
Modules§
- format
- Format detection, parsing and emission.
- value
- Conversion between the merge IR and the native JSON/TOML value types.
Structs§
- Cycle
- A reference that resolves, directly or indirectly, to itself.
- EnvValue
- An environment variable in both forms interpolation needs.
- Merge
Options - Knobs on the merge itself. Passed by reference rather than encoded as cargo
features: features are additive and unify across a dependency graph, so a
strictfeature would silently change behaviour for one consumer the moment a second consumer enabled it. - Path
Leaf - A leaf value addressed by a parsed path.
- Process
Env - Reads
${env:NAME}from the real environment. - RefPath
- A parsed path: dotted keys plus bracket array indices,
a.b[2].c.
Enums§
- Interp
Error - Why interpolation failed.
- Load
Error - Why a positional could not be turned into a layer.
- Merge
Error - Number
- A number, kept in the widest lossless representation of its source.
- Path
Error - Why a path expression was rejected.
- Problem
- One thing wrong with one reference.
- Seg
- One step of a path into a document.
- Syntax
- A malformed reference.
- Value
- A parsed document, or any node within one.
Constants§
- STDIN
- The positional that means “read stdin”.
Traits§
- Env
- Where
${env:NAME}reads from.
Functions§
- interpolate
- Resolves every reference in
doc. - json_
or_ string - Parses text as JSON, falling back to the string itself.
- load_
layers - Reads and parses every positional into the merge IR, keeping the format each input was read as.
- merge
- Folds a list of layers into one document, seeded with an empty object.
- merge_
into - Merges
overintobasein place. - render_
path - Renders a path for display:
servers.primary.host,tags[0].
Type Aliases§
- Map
- The object type.
indexmaprather thanBTreeMapso input key order survives, and rather thanVec<(String, Value)>so merge’s per-key lookup is not quadratic.