1pub trait Event: Clone {}
3
4pub trait EventHandler<E: Event> {
6 fn handle(&mut self, event: E);
8}
9
10#[cfg(feature = "async")]
12#[cfg_attr(feature = "async", async_trait::async_trait)]
13pub trait AsyncEventHandler<E: Event> {
14 async fn handle(&mut self, event: E);
16}
17
18impl<E, F> EventHandler<E> for F
21where
22 E: Event,
23 F: FnMut(E),
24{
25 fn handle(&mut self, event: E) {
26 self(event)
27 }
28}
29
30#[cfg(feature = "async")]
31#[cfg_attr(feature = "async", async_trait::async_trait)]
32impl<E, F> AsyncEventHandler<E> for F
33where
34 E: Event + Send + 'static,
35 F: FnMut(E) -> crate::futures::BoxFuture<'static, ()> + Send,
36{
37 async fn handle(&mut self, event: E) {
38 self(event).await
39 }
40}