Skip to main content

ModuleBuilder

Struct ModuleBuilder 

Source
pub struct ModuleBuilder { /* private fields */ }
Expand description

Collects what a module registers. Passed to Module::register.

Implementations§

Source§

impl ModuleBuilder

Source

pub fn module_id(&self) -> ModuleId

The id of the module being registered.

Source

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()
}
Source

pub fn import(&mut self, module: impl Module) -> &mut Self

Imports a module: its exports become visible to this module.

Source

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>>).

Source

pub fn global(&mut self) -> &mut Self

Marks the module global: its exports are visible to every module.

Source

pub fn provider<T: Injectable>(&mut self) -> &mut Self

Registers T under its unnamed key.

Source

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).

Source

pub fn value<T: Send + Sync + 'static>(&mut self, value: T) -> &mut Self

Registers an already-built singleton value.

Source

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>).

Source

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).

Source

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.

Source

pub fn exports<T: ?Sized + 'static>(&mut self) -> &mut Self

Exports the unnamed provider of T to importing modules.

Source

pub fn export_key(&mut self, key: ProviderKey) -> &mut Self

Exports a provider key (named or unnamed) to importing modules.

Source

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, …).

Source

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.

Source

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, ..).

Trait Implementations§

Source§

impl Debug for ModuleBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more