Skip to main content

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//!
30//! A module names itself a plugin with [`ModuleBuilder::plugin`] and
31//! [`plugin_info!`]; [`AppContext::plugins`] reports the plugins, and the
32//! built-in commands `plugins` and `plugin:publish` list them and copy the
33//! files they ship into the app.
34#![forbid(unsafe_code)]
35#![cfg_attr(docsrs, feature(doc_cfg))]
36
37#[cfg(not(panic = "unwind"))]
38compile_error!(
39    "navree requires `panic = \"unwind\"`: a panicking handler must not abort the whole server"
40);
41
42mod app;
43mod builder;
44mod collide;
45mod command;
46mod container;
47mod error;
48mod graph;
49mod introspect;
50mod key;
51mod lazy;
52mod lifecycle;
53mod module;
54mod plugin;
55mod plugin_graph;
56mod publish;
57mod report;
58mod resolver;
59
60pub use app::{App, AppBuilder, AppContext, Contributed, ModuleInfo, Navree, WeakAppContext};
61pub use builder::{Factory, ModuleBuilder};
62pub use command::{CommandFn, CommandSpec};
63pub use container::RequestScope;
64pub use error::{BootErrors, KernelError};
65pub use graph::{CommandInfo, GraphReport, ModuleReport, ProviderReport};
66pub use key::{ModuleId, ProviderKey, Scope};
67pub use lazy::Lazy;
68pub use lifecycle::Lifecycle;
69pub use module::{CodeConfigured, ConfiguredModule, Injectable, IntoModules, Module};
70pub use plugin::{PluginInfo, PublishTag, Publishable};
71pub use report::{PluginModuleReport, PluginReport, PluginsReport};
72pub use resolver::Resolver;
73
74/// Items Navree's own crates and macros use; not public API.
75#[doc(hidden)]
76pub mod __private {
77    pub use crate::builder::PassedModule;
78    pub use crate::collide::{
79        acts_for, acts_for_community_plugin, acts_for_reason, imports, is_app_module,
80        is_community_plugin,
81    };
82    pub use crate::command::FRAMEWORK_COMMANDS;
83    pub use crate::module::{ConfiguredPlainModule, PlainModule};
84    pub use crate::plugin::{
85        APP_ONLY_PROVIDERS, FIRST_PARTY, FRAMEWORK_CRATES, MODEL_HOOK_KEY, RESERVED_NAMESPACES,
86        default_namespace, is_namespace, namespace_text,
87    };
88    pub use crate::publish::is_safe_relative_path;
89    pub use crate::publish::{PublishRefused, Published, publish_files};
90    pub use crate::resolver::app_in_chain;
91}
92
93/// A boxed error that can cross module and task boundaries.
94pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
95
96/// A boxed, `Send` future (used where traits need to return futures as objects).
97pub type BoxFuture<'a, T> = std::pin::Pin<Box<dyn std::future::Future<Output = T> + Send + 'a>>;