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