navree_kernel/lib.rs
1//! # navree-kernel
2//!
3//! The Navree kernel: module graph, type-keyed dependency injection container,
4//! lifecycle hooks and the command runner. Everything else in Navree is a
5//! [`Module`].
6//!
7//! ```no_run
8//! use navree_kernel::{Navree, Module, ModuleBuilder};
9//!
10//! struct GreetingModule;
11//!
12//! impl Module for GreetingModule {
13//! fn register(&self, m: &mut ModuleBuilder) {
14//! m.value(String::from("hello")).exports::<String>();
15//! }
16//! }
17//!
18//! fn main() -> Result<(), navree_kernel::BoxError> {
19//! Navree::app().module(GreetingModule).run()
20//! }
21//! ```
22//!
23//! Rules: a module resolves its own providers, the exports of modules it
24//! imports directly and the exports of global modules. Singletons are built
25//! once (eagerly at boot, in module dependency order) and shared as `Arc<T>`.
26//! Wiring errors (missing or private providers, cycles, scope inversions,
27//! modules configured twice) fail the boot and name the module and the type.
28//! The kernel has no global statics.
29#![forbid(unsafe_code)]
30#![cfg_attr(docsrs, feature(doc_cfg))]
31
32#[cfg(not(panic = "unwind"))]
33compile_error!(
34 "navree requires `panic = \"unwind\"`: a panicking handler must not abort the whole server"
35);
36
37mod app;
38mod builder;
39mod command;
40mod container;
41mod error;
42mod graph;
43mod introspect;
44mod key;
45mod lazy;
46mod lifecycle;
47mod module;
48mod resolver;
49
50pub use app::{App, AppBuilder, AppContext, Contributed, ModuleInfo, Navree, WeakAppContext};
51pub use builder::{Factory, ModuleBuilder};
52pub use command::{CommandFn, CommandSpec};
53pub use container::RequestScope;
54pub use error::{BootErrors, KernelError};
55pub use graph::{CommandInfo, GraphReport, ModuleReport, ProviderReport};
56pub use key::{ModuleId, ProviderKey, Scope};
57pub use lazy::Lazy;
58pub use lifecycle::Lifecycle;
59pub use module::{CodeConfigured, ConfiguredModule, Injectable, IntoModules, Module};
60pub use resolver::Resolver;
61
62/// A boxed error that can cross module and task boundaries.
63pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
64
65/// A boxed, `Send` future (used where traits need to return futures as objects).
66pub type BoxFuture<'a, T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + Send + 'a>>;