pub struct ModuleBuilder { /* private fields */ }Expand description
Collects what a module registers. Passed to Module::register.
Implementations§
Source§impl ModuleBuilder
impl ModuleBuilder
Sourcepub fn plugin(&mut self, info: PluginInfo) -> &mut Self
pub fn plugin(&mut self, info: PluginInfo) -> &mut Self
Names this module a plugin. Call it once in register; several modules
of one crate may each call it with the same PluginInfo, and are then
one plugin. The kernel records it
(AppContext::plugin, the plugins
command) and checks its name, crate, version and namespace at boot.
Naming a plugin grants nothing.
A module that acts for a plugin which is not one of the framework’s own
packages may not configure a module of another crate, nor provide a
permission check, the route authorizer, the authenticator, a sign-in
strategy, the workspace gate, where native clients sign in, the options
of access, workspaces, authentication or the admin panel, the app’s
shell, its clock, an observer of every commit, the sink of its audit
records, its realtime backplane, or the fake that silences its model
listeners, nor hook a model of another crate, nor register a command with
the name of one of the framework’s own (plugins, check, ..): the
boot fails, and the app registers the plugin’s from a module of its own.
use navree_kernel::{Module, ModuleBuilder, Navree};
struct AnnouncementsModule;
impl Module for AnnouncementsModule {
fn register(&self, m: &mut ModuleBuilder) {
m.plugin(navree_kernel::plugin_info!(title = "Announcements"));
}
}
fn main() -> Result<(), navree_kernel::BoxError> {
Navree::app().module(AnnouncementsModule).run()
}Sourcepub fn import(&mut self, module: impl Module) -> &mut Self
pub fn import(&mut self, module: impl Module) -> &mut Self
Imports a module: its exports become visible to this module.
Sourcepub fn imports(&mut self, modules: impl IntoModules) -> &mut Self
pub fn imports(&mut self, modules: impl IntoModules) -> &mut Self
Imports several modules (a tuple of up to 16 modules or a Vec<Box<dyn Module>>).
Sourcepub fn global(&mut self) -> &mut Self
pub fn global(&mut self) -> &mut Self
Marks the module global: its exports are visible to every module.
Sourcepub fn provider<T: Injectable>(&mut self) -> &mut Self
pub fn provider<T: Injectable>(&mut self) -> &mut Self
Registers T under its unnamed key.
Sourcepub fn provider_named<T: Injectable>(
&mut self,
name: impl Into<Cow<'static, str>>,
) -> &mut Self
pub fn provider_named<T: Injectable>( &mut self, name: impl Into<Cow<'static, str>>, ) -> &mut Self
Registers T under name (resolved with Resolver::get_named).
Sourcepub fn value<T: Send + Sync + 'static>(&mut self, value: T) -> &mut Self
pub fn value<T: Send + Sync + 'static>(&mut self, value: T) -> &mut Self
Registers an already-built singleton value.
Sourcepub fn value_arc<T: ?Sized + Send + Sync + 'static>(
&mut self,
value: Arc<T>,
) -> &mut Self
pub fn value_arc<T: ?Sized + Send + Sync + 'static>( &mut self, value: Arc<T>, ) -> &mut Self
Registers an already-built singleton behind an Arc (also for Arc<dyn Trait>).
Sourcepub fn factory<T: ?Sized + Send + Sync + 'static>(
&mut self,
f: Factory<T>,
) -> &mut Self
pub fn factory<T: ?Sized + Send + Sync + 'static>( &mut self, f: Factory<T>, ) -> &mut Self
Registers a provider built by a Factory (unnamed unless Factory::named was used).
Sourcepub fn multi<T: ?Sized + Send + Sync + 'static>(
&mut self,
f: Factory<T>,
) -> &mut Self
pub fn multi<T: ?Sized + Send + Sync + 'static>( &mut self, f: Factory<T>, ) -> &mut Self
Adds a multi-binding of T. Every multi-binding of T in the app (in
module dependency order) is returned by Resolver::get_all and
AppContext::get_all; get::<T>() does not see them.
Sourcepub fn exports<T: ?Sized + 'static>(&mut self) -> &mut Self
pub fn exports<T: ?Sized + 'static>(&mut self) -> &mut Self
Exports the unnamed provider of T to importing modules.
Sourcepub fn export_key(&mut self, key: ProviderKey) -> &mut Self
pub fn export_key(&mut self, key: ProviderKey) -> &mut Self
Exports a provider key (named or unnamed) to importing modules.
Sourcepub fn contribute<C: Send + Sync + 'static>(&mut self, c: C) -> &mut Self
pub fn contribute<C: Send + Sync + 'static>(&mut self, c: C) -> &mut Self
Contributes a value that other modules collect with
AppContext::contributions
(routes, migrations, job registrations, …).
Sourcepub fn lifecycle<T: Lifecycle + Send + Sync + 'static>(&mut self) -> &mut Self
pub fn lifecycle<T: Lifecycle + Send + Sync + 'static>(&mut self) -> &mut Self
Runs the Lifecycle hooks of provider T, which must be a provider
of this module.
Sourcepub fn command(&mut self, cmd: CommandSpec) -> &mut Self
pub fn command(&mut self, cmd: CommandSpec) -> &mut Self
Registers a CLI command (names must be unique across the app). A module
of a plugin that is not one of the framework’s own may not take the name
of one of the framework’s commands (plugins, check, help, ..).