use futures::Future; pub trait Executor { fn spawn(&self, future: impl Future + Send + 'static); fn enter(&self, f: impl FnOnce() -> R) -> R { f() } } impl Executor for futures::executor::ThreadPool { fn spawn(&self, future: impl Future + Send + 'static) { self.spawn_ok(future); } } #[cfg(feature = "tokio")] impl Executor for tokio::runtime::Runtime { fn spawn(&self, future: impl Future + Send + 'static) { let _ = tokio::runtime::Runtime::spawn(self, future); } fn enter(&self, f: impl FnOnce() -> R) -> R { tokio::runtime::Runtime::enter(self, f) } }