pub trait LightweightModule<S: AppState>: Send + 'static {
// Required methods
fn new(
state: Arc<S>,
ws_sender: AsyncSender<Message>,
ws_receiver: AsyncReceiver<Arc<Message>>,
runner_command_tx: AsyncSender<RunnerCommand>,
) -> Self
where Self: Sized;
fn run<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = CoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn rule() -> Box<dyn Rule + Send + Sync>;
}Expand description
A self‐contained module that runs independently,
owns its recv/sender channels and shared state,
and processes incoming WS messages according to its routing rule.
It’s main difference from ApiModule is that it does not
require a command-response mechanism and is not intended to be used
as a part of the API, but rather as a lightweight module that can
process messages in a more flexible way.
It is useful for modules that need to handle messages without the overhead of a full API module
and can be used for tasks like logging, monitoring, or simple message transformations.
It is designed to be lightweight and efficient, allowing for quick processing of messages
without the need for a full command-response cycle.
It is also useful for modules that need to handle messages in a more flexible way,
such as forwarding messages to other parts of the system or performing simple transformations.
It is not intended to be used as a part of the API, but rather as a
lightweight module that can process messages in a more flexible way.
The main difference from the LightweightHandler type is that this trait is intended for
modules that need to manage their own state and processing logic and being run in a dedicated task.,
allowing easy automation of things like sending periodic messages to a websocket connection to keep it alive.
Required Methods§
Sourcefn new(
state: Arc<S>,
ws_sender: AsyncSender<Message>,
ws_receiver: AsyncReceiver<Arc<Message>>,
runner_command_tx: AsyncSender<RunnerCommand>,
) -> Selfwhere
Self: Sized,
fn new(
state: Arc<S>,
ws_sender: AsyncSender<Message>,
ws_receiver: AsyncReceiver<Arc<Message>>,
runner_command_tx: AsyncSender<RunnerCommand>,
) -> Selfwhere
Self: Sized,
Construct the module with:
- shared app state
- a sender for outgoing WS messages
- a receiver for incoming WS messages
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.