Skip to content

Module and slots ​

crates/api/src/module.rs.

rust
pub struct Module {
    pub name: &'static str,                 // unique in the binary
    pub requires: &'static [&'static str],  // modules whose points or services are used
    pub provides: &'static [Provide],
}

Everything is static (const): a module registers nothing at run time, its description is data checked by Modules::new and parsed as text by the binary's build.rs (Build). Hence the requirements on the form of the description:

  • the constant is declared as const NAME: ours_api::Module = ours_api::Module { ... } (or : Module = Module {);
  • name, keys, points, section and schema names are string literals right in the body;
  • the description is outside #[cfg(test)] mod tests.

requires may be a constant with cfg (vless requires mux only with the mux feature); build.rs does not read requires.

Usually the module name matches the name of the binary's Cargo feature that enables it: it appears in "not built in (feature <name>)" messages.

Slot ​

Provide::slot() — where a contribution goes and under which key. Two modules of one build cannot take the same slot.

ProvideSlot (point, key)
Inbound { key }("inbounds", key)
Outbound { key }("outbounds", key)
Endpoint { key }("endpoints", key)
RuleSets(_)("rule_sets", "")
Rules(_)("rules", "")
Dns(_)("dns", "")
Dispatcher(_)("dispatcher", "")
Point(name)("points", name)
Extension { point, key }(point, key)
Block { block, key }(block, key)
Section { key }("sections", key)
RuleSet { key }("rule_sets", key)
Schema { name }("schemas", name)
Condition(entry)("conditions", entry.key)
Unit, Blocks, Source, Checkno slot — there may be any number of them

Singletons (RuleSets, Rules, Dns, Dispatcher) have an empty key: there is at most one in a build. RuleSets (the factory) and RuleSet { key } (the remote/file/inline source) share the rule_sets point, but with different keys.

Provide::extension() — for Extension, Condition and Block (its BlockDecoder) returns (point, key, &dyn Any); Extensions is assembled from them (Points and extensions).

Known ​

rust
pub struct Known { pub module: &'static str, pub provides: &'static [(&'static str, &'static str)] }

A workspace module and its slots — regardless of whether it is built. The KNOWN table is generated by build.rs; the kernel gets it through Modules::with_known and tells apart in errors "this module is not built in" from "no such thing at all". The binary's test compares the slots from KNOWN with the slots of LIST.

Workspace modules ​

The list with what each one provides — Modules.

GPL-3.0-or-later