English
Module order and Modules::new
crates/kernel/src/modules.rs. Modules is the checked module list of the binary, through which the kernel gets everything else.
Checks of Modules::new(list)
The list is static (&'static [Module]), so any error is a defect of the binary, not of the configuration; it is caught by the the_list_is_sound test in app/ours/src/modules.rs.
| Check | Error |
|---|---|
| the module name is unique | module x is listed twice |
each of requires is in the list | module xrequiresy, which is not built in |
Provide::slot slots do not repeat (by the pair (point, key)) | modules aandbboth providekofp`` |
an Extension/Block extends a point someone opened (Provide::Point) | module xextendsp, which no module opens |
| a module extending someone else's point requires its owner | module xextendspofy without requiring it |
there is no cycle in requires | modules require each other in a cycle: a, b |
exactly one Provide::Dispatcher (two are caught by the slot check) | no module provides the dispatcher |
The same key at different points is not a conflict: a slot is the pair (point, key). A module may extend its own point without requires (this is how router adds the dns condition to its own point conditions). Slots: Module.
Order
ordered() is a topological sort that preserves the original order: at every step the first module in the list whose requires are all already ordered is taken. This order determines:
- the order in which units are built (
Unit::build) — a unit sees the services published by the units of the modules its module requires; - the order in which units are closed — the reverse;
- the lookup of factories and decoders — the first matching
Provide(slot uniqueness makes it the only one).
What Modules hands out
decoders()—ours_api::config::Decodersfor the loader: block decoders (Block,Inbound,Outbound), which blocks each type takes (Blocks), point extensions, sections, sources (Source), checks (Check), JSON Schema parts, rule-set sources; plus the kernel's own — theown()function: thelog,reload,runtime,routesections (except what belongs to modules) and thereloadblock of inbound/outbound. The loader is described in Configuration.inbound(key),outbound(key)— factories; if absent — an error with the available keys and a "not built in" note (with_known, see Building the binary).rule_sets(),rules(),dns()—Option: without a module the kernel takes the stubsno_rule_sets,no_rules(crates/kernel/src/adapter.rs) andno_dns— they allow only a configuration without rule-sets, rules and DNS.dispatcher()— the dispatcher factory (its presence is checked innew).units()— an instance of everyProvide::Unit(called once perInstance).section(key)— an error for a section that no module of the build reads.extensions()—Arc<Extensions>: all variants of the build's points; the kernel publishes it as a service.has(point, key),key(point, key),names()— for the binary and the UI.
own() and the route section
route is decoded by the kernel (RouteOptions, crates/config/src/options/route.rs), but rules and rule-sets — by the router module (the route.rules, route.default_http_client sections). If route contains default_http_client and there is no router, own() answers "not built in (feature router)".