1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
use crate::MinerList; use async_std::future::Future; use async_std::sync::Arc; use async_trait::async_trait; #[async_trait] pub trait Global<State: Clone + Send + Sync + 'static>: Send + Sync + 'static { async fn call(&self, state: State, connection_list: Arc<MinerList>); } #[async_trait] impl<State, F, Fut> Global<State> for F where State: Clone + Send + Sync + 'static, F: Send + Sync + 'static + Fn(State, Arc<MinerList>) -> Fut, Fut: Future<Output = ()> + Send + 'static, { async fn call(&self, state: State, connection_list: Arc<MinerList>) { let fut = (self)(state.clone(), connection_list.clone()); fut.await; } }