1use async_scoped::spawner::{Blocker, FuncSpawner, Spawner};
15use futures::Future;
16
17pub(crate) mod abort;
18
19pub trait Runtime: 'static {
21 type ScopedSpawner: Spawner<()>
23 + FuncSpawner<(), SpawnHandle = <Self::ScopedSpawner as Spawner<()>>::SpawnHandle>
24 + Blocker
25 + Default
26 + Send
27 + Sync
28 + 'static;
29
30 type BlockingRunner: BlockingRunner;
32}
33
34pub trait BlockingRunner: 'static {
36 fn block_on<F: Future>(fut: F) -> F::Output;
38}
39
40#[cfg(feature = "tokio")]
42#[allow(missing_debug_implementations)]
43pub enum Tokio {}
44
45#[cfg(feature = "tokio")]
47pub mod tokio {
48 #![allow(missing_debug_implementations)]
49 use super::*;
50
51 impl Runtime for Tokio {
52 type ScopedSpawner = async_scoped::spawner::use_tokio::Tokio;
53 type BlockingRunner = TokioBlockingRunner;
54 }
55
56 pub struct TokioBlockingRunner;
58 impl BlockingRunner for TokioBlockingRunner {
59 fn block_on<F: Future>(fut: F) -> F::Output {
60 ::tokio::runtime::Handle::current().block_on(fut)
61 }
62 }
63}
64
65#[cfg(feature = "async-std")]
67#[allow(missing_debug_implementations)]
68pub enum AsyncStd {}
69
70#[cfg(feature = "async-std")]
72pub mod async_std {
73 #![allow(missing_debug_implementations)]
74 use super::*;
75
76 impl Runtime for AsyncStd {
77 type ScopedSpawner = async_scoped::spawner::use_async_std::AsyncStd;
78 type BlockingRunner = AsyncStdBlockingRunner;
79 }
80
81 pub struct AsyncStdBlockingRunner;
83 impl BlockingRunner for AsyncStdBlockingRunner {
84 fn block_on<F: Future>(fut: F) -> F::Output {
85 ::async_std::task::block_on(fut)
86 }
87 }
88}