Skip to main content

Crate lumen_capability

Crate lumen_capability 

Source
Expand description

Optional runtime subsystems, and the list they put themselves on.

The run loop installs a fixed core (layout, input, text, the reactive bindings) and then whatever optional subsystems the binary carries: a tray icon host, the HTTP client, the introspection server, the devtools overlay. It does not name any of them, nor the backends (the layout engine, the window system, the renderers) it finds in their registries. Each one is a Capability that its own crate registers before main through lumen_capability!, and the run loop reads the list at the Phase each entry asked for.

That shape is what lets a link decide which subsystems an app carries. The macro exports one symbol per capability, and a link that names the symbol pulls the subsystem in while a link that does not leaves it out, with no compiler in the loop; see the macro crate’s docs for the mechanics. A plain cargo build links every capability its graph holds, so the default engine behaves as it always did.

use lumen_capability::{CapabilityEnv, Phase, lumen_capability};
use lumen_core::app::App;
use lumen_core::tick::TickStage;

fn poll_beeper() {}

fn install(app: &mut App, env: &CapabilityEnv) {
    // Skip the whole subsystem for an app that provably never beeps.
    if env.sources_mention(&["beep("]) {
        app.add_systems(TickStage::Systems, poll_beeper);
    }
}

lumen_capability!("beeper", Phase::Platform, install);

An entry may also carry a preflight, run before the app is built, for a subsystem that has to answer before any other work starts (a second instance of a single-instance app exits from there).

Macros§

lumen_capability
Declare an optional runtime subsystem.

Structs§

Capability
One optional subsystem linked into the running binary.
CapabilityEnv
What a capability is installed with: the app’s location, identity, and configuration, the run mode, and a bounded view of its sources.

Enums§

Phase
Where in the app build a capability is installed.
Preflight
What a preflight decides.
Select
When a link that picks its capabilities carries this one.

Constants§

REGISTER_PREFIX
The prefix of the register symbol every capability exports; the declared name completes it. Naming it on a link line is what pulls a capability out of an archive that nothing else references.

Functions§

derive_app_id
The app id a directory name gives: lowercased, every character that is not a letter or digit replaced by -, lumen-app when nothing is left. The same rule the runtime applies, spelled here so an environment built with no runtime in the process derives the same id.
install_phase
Install every capability registered for phase, in name order.
preflight
Run every preflight, in install order. The first one that asks to exit ends the walk.
register
Add a capability to the list.
register_symbol
The register symbol of the capability called name: the prefix, then the name with every character a symbol cannot carry replaced by _.
registered
The registered capabilities, in install order: by phase, then by name. Copied out so the caller holds no lock while it installs them.