1use std::{future::Future, pin::Pin};
3
4pub trait Executor: ExecutorClone {
5 fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>);
7}
8
9pub trait ExecutorClone {
10 fn clone_box(&self) -> Box<dyn Executor + Send + Sync>;
11}
12
13impl<T> ExecutorClone for T
14where
15 T: 'static + Executor + Clone + Send + Sync,
16{
17 fn clone_box(&self) -> Box<dyn Executor + Send + Sync> {
18 Box::new(self.clone())
19 }
20}
21
22impl Clone for Box<dyn Executor + Send + Sync> {
23 fn clone(&self) -> Box<dyn Executor + Send + Sync> {
24 self.clone_box()
25 }
26}
27
28#[derive(Clone)]
29pub struct TokioExecutor;
30
31impl Executor for TokioExecutor {
32 fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>) {
33 tokio::task::spawn(future);
34 }
35}
36
37impl Default for TokioExecutor {
38 fn default() -> Self {
39 TokioExecutor
40 }
41}