Skip to main content

MessageHandler

Trait MessageHandler 

Source
pub trait MessageHandler<T: Send + Sync + 'static>:
    Send
    + Sync
    + 'static {
    // Required method
    fn handle<'life0, 'async_trait>(
        &'life0 self,
        msg: Message<T>,
    ) -> Pin<Box<dyn Future<Output = AppResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Handler for processing consumed messages.

Implement this trait to define how incoming messages are processed. For simple cases, use FnHandler to wrap a closure.

Required Methods§

Source

fn handle<'life0, 'async_trait>( &'life0 self, msg: Message<T>, ) -> Pin<Box<dyn Future<Output = AppResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Process a single message.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<T, F, Fut> MessageHandler<T> for FnHandler<T, F, Fut>
where T: Send + Sync + 'static, F: Fn(Message<T>) -> Fut + Send + Sync + 'static, Fut: Future<Output = AppResult<()>> + Send + 'static,