Skip to main content

Crate knf

Crate knf 

Source
Expand description

Load, merge and emit layered JSON and TOML configuration.

Three steps, each a function, and a caller composes them:

  1. load_layers reads each path into a Value, keeping the format it was read as;
  2. merge folds the flat layer list from left to right — any in-memory overlays are just more layers appended to the list;
  3. 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.
MergeOptions
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 strict feature would silently change behaviour for one consumer the moment a second consumer enabled it.
PathLeaf
A leaf value addressed by a parsed path.
ProcessEnv
Reads ${env:NAME} from the real environment.
RefPath
A parsed path: dotted keys plus bracket array indices, a.b[2].c.

Enums§

InterpError
Why interpolation failed.
LoadError
Why a positional could not be turned into a layer.
MergeError
Number
A number, kept in the widest lossless representation of its source.
PathError
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 over into base in place.
render_path
Renders a path for display: servers.primary.host, tags[0].

Type Aliases§

Map
The object type. indexmap rather than BTreeMap so input key order survives, and rather than Vec<(String, Value)> so merge’s per-key lookup is not quadratic.