Skip to main content

async_rt/rt/
dummy.rs

1use crate::{Executor, ExecutorBlockOn, ExecutorBlocking, ExecutorTimeout, JoinHandle};
2
3/// Placeholder executor that does not provide task execution.
4///
5/// All execution methods panic when called.
6#[derive(Default, Clone, Copy, Debug, PartialOrd, PartialEq, Eq)]
7pub struct DummyExecutor;
8
9impl Executor for DummyExecutor {
10    fn runtime_type(&self) -> Option<&'static str> {
11        Some("dummy")
12    }
13
14    fn spawn<F>(&self, _: F) -> JoinHandle<F::Output>
15    where
16        F: Future + Send + 'static,
17        F::Output: Send + 'static,
18    {
19        missing_runtime()
20    }
21}
22
23impl ExecutorBlocking for DummyExecutor {
24    fn spawn_blocking<F, R>(&self, _: F) -> JoinHandle<R>
25    where
26        F: FnOnce() -> R + Send + 'static,
27        R: Send + 'static,
28    {
29        missing_runtime()
30    }
31}
32
33impl ExecutorTimeout for DummyExecutor {}
34
35impl ExecutorBlockOn for DummyExecutor {
36    fn block_on<F: Future>(&self, _: F) -> F::Output {
37        missing_runtime()
38    }
39}
40
41#[cold]
42#[track_caller]
43fn missing_runtime() -> ! {
44    panic!("DummyExecutor does not provide a runtime backend")
45}