Skip to main content

Crate navree_kernel

Crate navree_kernel 

Source
Expand description

The Navree kernel: module graph, type-keyed dependency injection container, lifecycle hooks and the command runner. Everything else in Navree is a Module.

use navree_kernel::{Navree, Module, ModuleBuilder};

struct GreetingModule;

impl Module for GreetingModule {
    fn register(&self, m: &mut ModuleBuilder) {
        m.value(String::from("hello")).exports::<String>();
    }
}

fn main() -> Result<(), navree_kernel::BoxError> {
    Navree::app().module(GreetingModule).run()
}

Rules: a module resolves its own providers, the exports of modules it imports directly and the exports of global modules. Singletons are built once (eagerly at boot, in module dependency order) and shared as Arc<T>. Wiring errors (missing or private providers, cycles, scope inversions, modules configured twice) fail the boot and name the module and the type. The kernel has no global statics.

A module names itself a plugin with ModuleBuilder::plugin and plugin_info!; AppContext::plugins reports the plugins, and the built-in commands plugins and plugin:publish list them and copy the files they ship into the app.

Macros§

plugin_info
What a plugin says about itself, filled from the Cargo.toml of the crate that calls it: a PluginInfo with the calling crate’s CARGO_PKG_NAME, CARGO_CRATE_NAME, CARGO_PKG_VERSION, CARGO_PKG_DESCRIPTION, CARGO_PKG_HOMEPAGE, CARGO_PKG_REPOSITORY and CARGO_PKG_LICENSE (an empty value gives None).

Structs§

App
A booted app. Dropping it without shutdown cancels the shutdown token but runs no hooks.
AppBuilder
Collects the root modules of an app, then validates, boots or runs it.
AppContext
A cheap, cloneable handle to a booted app.
BootErrors
Every error found while booting or validating an app.
CodeConfigured
Contributed by a module that was given its options in code (for_root(options)), so tools can tell that the section of the configuration it would otherwise read is not read. navree-config warns when the configuration has such a section.
CommandInfo
One command of a ModuleReport.
CommandSpec
A command a module registers with ModuleBuilder::command, run as <binary> <name> [args...] against a booted app.
ConfiguredModule
The configured form of module M: what M::for_root(options) and M::from_config() return, so a module does not repeat the wrapper that carries its id, says it is configured and hands its options to register.
Contributed
A value contributed with ModuleBuilder::contribute and the module that contributed it.
Factory
A provider definition for an Arc<T> built by an async closure. Use it for trait objects (Factory::<dyn Mailer>::new(...)), named providers and values that need async setup.
GraphReport
The validated module graph, as printed by check --graph.
Lazy
A handle to the unnamed provider of T, resolved (with the visibility of the module that created it) on the first get and then cached.
ModuleBuilder
Collects what a module registers. Passed to Module::register.
ModuleId
Identity of a module: its Rust type plus a readable name.
ModuleInfo
A module of a booted app.
ModuleReport
One module of a GraphReport.
Navree
Entry point: Navree::app().module(...).run().
PluginInfo
What a plugin says about itself: m.plugin(plugin_info!()).
PluginModuleReport
One module of a PluginReport.
PluginReport
One plugin of a PluginsReport.
PluginsReport
Every plugin of an app and what each of its modules adds: what the plugins command prints (its Display text, or to_json with --json). Read from the module graph; nothing is built to make it.
ProviderKey
Key of a provider in the container: a type plus an optional name, so Db and Db("analytics") can coexist.
ProviderReport
One provider of a ModuleReport.
Publishable
Files a plugin ships in its binary that plugin:publish copies into the app, all under one PublishTag. A module that names itself a plugin contributes it with m.contribute(..).
RequestScope
The cache of one unit of work (an HTTP request, a job run, a command, …): request-scoped providers are built at most once per RequestScope. Clones share the same cache.
Resolver
Resolves providers with the visibility of one module: its own providers, the exports of the modules it imports and the exports of global modules.
WeakAppContext
A weak handle to a booted app (AppContext::downgrade): it does not keep the app alive, and upgrade returns None once the app is dropped.

Enums§

KernelError
An error raised while validating the module graph, resolving a provider, running a lifecycle hook or dispatching a command.
PublishTag
The kinds of files a plugin ships that plugin:publish copies into the app, each into a folder of its own (relative to the app’s folder):
Scope
How long a provided instance lives.

Traits§

Injectable
A type the container can construct (what #[injectable] implements).
IntoModules
Values accepted by ModuleBuilder::imports: a module, a tuple of up to 16 modules, or a Vec<Box<dyn Module>>.
Lifecycle
Hooks implemented by a provider and registered with ModuleBuilder::lifecycle.
Module
A unit of an app: it registers providers, exports, imports, contributions, lifecycle hooks and commands through a ModuleBuilder.

Type Aliases§

BoxError
A boxed error that can cross module and task boundaries.
BoxFuture
A boxed, Send future (used where traits need to return futures as objects).
CommandFn
The function behind a CommandSpec.