Trait EventHandler

Source
pub trait EventHandler:
    Send
    + Sync
    + 'static {
    // Required method
    fn handle_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event: &'life1 Event,
    ) -> Pin<Box<dyn Future<Output = Result<(), EventError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A trait for handling events emitted by the event bus

Implementors of this trait can be registered with the EventBus to receive and process events. The handler is called asynchronously for each event emitted.

§Errors

Returns an [Error] if event handling fails. The error will be propagated back through the event bus.

§Examples

struct MyHandler;

#[async_trait]
impl EventHandler for MyHandler {
    async fn handle(&self, event: &Event) -> Result<(), Error> {
        // Handle the event...
        Ok(())
    }
}

Required Methods§

Source

fn handle_event<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Event, ) -> Pin<Box<dyn Future<Output = Result<(), EventError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§