criterion/
async_executor.rs1use std::future::Future;
15
16pub trait AsyncExecutor {
21 fn block_on<T>(&self, future: impl Future<Output = T>) -> T;
23}
24
25#[cfg(feature = "async_futures")]
27pub struct FuturesExecutor;
28#[cfg(feature = "async_futures")]
29impl AsyncExecutor for FuturesExecutor {
30 fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
31 futures::executor::block_on(future)
32 }
33}
34
35#[cfg(feature = "async_smol")]
37pub struct SmolExecutor;
38#[cfg(feature = "async_smol")]
39impl AsyncExecutor for SmolExecutor {
40 fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
41 smol::block_on(future)
42 }
43}
44
45#[cfg(feature = "async_tokio")]
46impl AsyncExecutor for tokio::runtime::Runtime {
47 fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
48 self.block_on(future)
49 }
50}
51#[cfg(feature = "async_tokio")]
52impl AsyncExecutor for &tokio::runtime::Runtime {
53 fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
54 (*self).block_on(future)
55 }
56}
57
58#[cfg(feature = "async_std")]
60pub struct AsyncStdExecutor;
61#[cfg(feature = "async_std")]
62impl AsyncExecutor for AsyncStdExecutor {
63 fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
64 async_std::task::block_on(future)
65 }
66}