Skip to main content

Module

Trait Module 

Source
pub trait Module:
    Send
    + Sync
    + 'static {
    // Required methods
    fn metadata(&self) -> ModuleMetadata;
    fn start<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn init<'life0, 'async_trait>(
        &'life0 mut self,
        _bus: MessageBus,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait implemented by all native, in-process modules.

Methods are async because most kernel work flows through Tokio and many modules need to await I/O during start/stop. Implementors should not block the runtime in these hooks.

Required Methods§

Source

fn metadata(&self) -> ModuleMetadata

Static module metadata.

Source

fn start<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the module. Must be idempotent.

Source

fn stop<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stop the module. Must be idempotent and quick; long-running cleanup belongs in a separate task signalled from here.

Provided Methods§

Source

fn init<'life0, 'async_trait>( &'life0 mut self, _bus: MessageBus, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Initialize the module. Called once, before start.

The bus is provided so the module can subscribe to events or publish initial state. The default implementation is a no-op.

Implementors§