orsomafo 0.5.1

Event dispatcher crate
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::{DispatchedEvent, EventHandler};
use async_trait::async_trait;
use futures::future::BoxFuture;

#[derive(Default)]
pub(crate) struct ClosureHandlerWrapper<F>(pub(crate) F)
where
    F: Fn(DispatchedEvent) -> BoxFuture<'static, ()> + Send + Sync + 'static;

#[async_trait]
impl<F> EventHandler for ClosureHandlerWrapper<F>
where
    F: Fn(DispatchedEvent) -> BoxFuture<'static, ()> + Send + Sync + 'static,
{
    async fn handle(&self, event: DispatchedEvent) {
        (self.0)(event).await;
    }
}