pub struct ModuleBuilder { /* private fields */ }Expand description
Collects what a module registers. Passed to Module::register.
Implementations§
Source§impl ModuleBuilder
impl ModuleBuilder
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).