Skip to main content

Module

Trait Module 

Source
pub trait Module:
    Send
    + Sync
    + 'static {
    // Required method
    fn name(&self) -> &'static str;

    // Provided methods
    fn imports(&self) -> Vec<Arc<dyn Module>> { ... }
    fn providers(&self) -> Result<Vec<ProviderDefinition>> { ... }
    fn controllers(
        &self,
        _module_ref: &ModuleRef,
    ) -> Result<Vec<ControllerDefinition>> { ... }
    fn routes(&self) -> Result<Vec<RouteDefinition>> { ... }
    fn on_module_init(&self, _module_ref: &ModuleRef) -> Result<()> { ... }
    fn on_application_bootstrap(
        &self,
        _module_ref: ModuleRef,
    ) -> BoxFuture<'static, Result<()>> { ... }
    fn on_application_shutdown(
        &self,
        _module_ref: ModuleRef,
    ) -> BoxFuture<'static, Result<()>> { ... }
}
Expand description

A module contributes imports, providers, controllers, and routes.

This is the Rust equivalent of a Nest module boundary. Modules organize the application graph; HTTP serving remains delegated to an adapter.

Required Methods§

Source

fn name(&self) -> &'static str

Stable module name used for deduplication and diagnostics.

Provided Methods§

Source

fn imports(&self) -> Vec<Arc<dyn Module>>

Imported modules that should be registered before this module.

Source

fn providers(&self) -> Result<Vec<ProviderDefinition>>

Providers exported into the application container.

Source

fn controllers( &self, _module_ref: &ModuleRef, ) -> Result<Vec<ControllerDefinition>>

Controller route groups built with access to the provider container.

Source

fn routes(&self) -> Result<Vec<RouteDefinition>>

Framework-neutral routes contributed directly by this module.

Source

fn on_module_init(&self, _module_ref: &ModuleRef) -> Result<()>

Lifecycle hook called after imports and providers are registered.

Source

fn on_application_bootstrap( &self, _module_ref: ModuleRef, ) -> BoxFuture<'static, Result<()>>

Async lifecycle hook called by hosts that want startup work before serve.

Source

fn on_application_shutdown( &self, _module_ref: ModuleRef, ) -> BoxFuture<'static, Result<()>>

Async lifecycle hook called by hosts that need graceful shutdown cleanup.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§