///! A simple trait to allow generic executors or wrappers for spawning the discv5 tasks. use std::future::Future; use std::pin::Pin; pub trait Executor: ExecutorClone { /// Run the given future in the background until it ends. fn spawn(&self, future: Pin + Send>>); } pub trait ExecutorClone { fn clone_box(&self) -> Box; } impl ExecutorClone for T where T: 'static + Executor + Clone + Send + Sync, { fn clone_box(&self) -> Box { Box::new(self.clone()) } } impl Clone for Box { fn clone(&self) -> Box { self.clone_box() } } #[derive(Clone)] pub struct TokioExecutor; impl Executor for TokioExecutor { fn spawn(&self, future: Pin + Send>>) { tokio::task::spawn(future); } } impl Default for TokioExecutor { fn default() -> Self { TokioExecutor } }