Skip to main content
The Module trait is the foundation for all modules in the iii framework. Every module must implement this trait to integrate with the engine’s lifecycle management, function registration, and background task execution.

Location

Defined in src/modules/module.rs

Trait Definition

Required Methods

name

Returns the static name of the module.
&'static str
The module’s name identifier

create

Creates a new instance of the module. This is the primary constructor method.
Arc<Engine>
required
Reference to the iii engine instance
Option<Value>
Optional JSON configuration for the module
anyhow::Result<Box<dyn Module>>
Returns a boxed module instance or an error

initialize

Initializes the module. Called after creation and before the module is used.
anyhow::Result<()>
Returns Ok(()) on success or an error

Optional Methods

make_module

Helper method to create a module future. Has a default implementation that calls create.
Arc<Engine>
required
Reference to the iii engine instance
Option<Value>
Optional JSON configuration for the module
ModuleFuture
A pinned future that resolves to a module instance

start_background_tasks

Starts any background tasks required by the module. Default implementation does nothing.
tokio::sync::watch::Receiver<bool>
required
Shutdown signal receiver to gracefully stop background tasks
anyhow::Result<()>
Returns Ok(()) on success or an error

destroy

Cleans up module resources during shutdown. Default implementation logs and returns Ok.
anyhow::Result<()>
Returns Ok(()) on success or an error

register_functions

Registers the module’s functions with the engine. Usually overridden by the #[service] macro.
Arc<Engine>
required
Reference to the iii engine instance for function registration

Implementation Example

ModuleFuture

A pinned boxed future that resolves to a Module instance.

See Also