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

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