Skip to main content

Module engine

Module engine 

Source
Expand description

The resolution engine: the thing that folds the collected layers.

A load walks its sources itself — discovery, decryption, sections, the environment and the .env files are this crate’s, and no engine sees a file. What an engine does is the step after that: take one tree per layer, in precedence order, and answer with the merged tree and which layer won each leaf.

defaults   {host: localhost, port: 5432}   tag 0
file       {host: db.internal}             tag 1
env        {port: 6543}                    tag 2
           ──────────── fold ────────────
values     {host: db.internal, port: 6543}
tags       host → 1, port → 2

Every engine here implements the same rule — tables descend, everything else replaces, arrays included — so which one is installed is not a question about what a configuration means. That is not a hope: the whole composition corpus, a generated corpus of layer stacks, and the corner cases where a backend’s own habits could show through all run through every engine, and both the tree and the winner of every leaf are compared.

Where a backend disagrees, the adapter is what gives way. One of them reads a top-level key as a path expression, which would turn {"my.module": "debug"} into a nested table; its adapter hands over stand-in names and puts the document’s own back afterwards. Another records provenance per provider and cannot answer for a key with a dot in it; the fold fills that in from the layers it was given.

Two ship:

enginefeaturewhat it is
config_rs()the fold of the config crate; the default
figment()figmentthe fold of the figment crate

A third is anything implementing Engine: the trait deals in this crate’s Value and in opaque tags, so nothing about a backend reaches it. This crate keeps no fold of its own — it wrote one, proved the others against it, and then deleted it rather than maintain a second implementation of somebody else’s rule.

Structs§

Folded
What an engine hands back.
Layer
One layer, on its way into an engine.

Traits§

Engine
A fold, and where each leaf came from.

Functions§

all
Every engine this build ships, lowest-level first.
config_rs
The config crate’s fold.
figmentfigment
The figment crate’s fold.
has_engine
Whether an engine has been installed.
set_engine
Installs engine for every load in this process that does not name one.