use {async_trait::async_trait, std::future::Future}; type Ref = std::sync::Arc; #[async_trait] pub trait Worker: Send + Sync { async fn execute(&self, state: Ref, event: E1); } #[async_trait] impl Worker for F1 where F1: Fn(Ref, E1) -> R1, R1: Future, { async fn execute(&self, state: Ref, event: E1) { (*self)(state, event).await } } #[async_trait] pub trait MappedWorker: Send + Sync { async fn execute(&self, event: E1); } #[async_trait] impl MappedWorker for F1 where F1: Fn(E1) -> R1, R1: Future, { async fn execute(&self, event: E1) { (*self)(event).await } }