1use crate::error::TimeoutError;
2use crate::{
3 AbortableJoinHandle, Executor, ExecutorBlockOn, ExecutorBlocking, ExecutorTimeout, JoinHandle,
4};
5use std::future::Future;
6use std::rc::Rc;
7use std::time::Duration;
8
9impl<E> Executor for Rc<E>
10where
11 E: Executor,
12{
13 fn runtime_type(&self) -> Option<&'static str> {
14 (**self).runtime_type()
15 }
16 fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
17 where
18 F: Future + Send + 'static,
19 F::Output: Send + 'static,
20 {
21 (**self).spawn(future)
22 }
23}
24
25impl<E> ExecutorBlocking for Rc<E>
26where
27 E: ExecutorBlocking,
28{
29 fn spawn_blocking<F, R>(&self, f: F) -> JoinHandle<R>
30 where
31 F: FnOnce() -> R + Send + 'static,
32 R: Send + 'static,
33 {
34 (**self).spawn_blocking(f)
35 }
36}
37
38impl<E> ExecutorTimeout for Rc<E>
39where
40 E: ExecutorTimeout,
41{
42 fn spawn_timeout<F>(
43 &self,
44 duration: Duration,
45 f: F,
46 ) -> JoinHandle<Result<F::Output, TimeoutError>>
47 where
48 F: Future + Send + 'static,
49 F::Output: Send + 'static,
50 {
51 (**self).spawn_timeout(duration, f)
52 }
53
54 fn spawn_delay<F>(&self, duration: Duration, f: F) -> JoinHandle<F::Output>
55 where
56 F: Future + Send + 'static,
57 F::Output: Send + 'static,
58 {
59 (**self).spawn_delay(duration, f)
60 }
61
62 fn spawn_abortable_timeout<F>(
63 &self,
64 duration: Duration,
65 f: F,
66 ) -> AbortableJoinHandle<Result<F::Output, TimeoutError>>
67 where
68 F: Future + Send + 'static,
69 F::Output: Send + 'static,
70 {
71 (**self).spawn_abortable_timeout(duration, f)
72 }
73
74 fn spawn_abortable_delay<F>(&self, duration: Duration, f: F) -> AbortableJoinHandle<F::Output>
75 where
76 F: Future + Send + 'static,
77 F::Output: Send + 'static,
78 {
79 (**self).spawn_abortable_delay(duration, f)
80 }
81}
82
83impl<E> ExecutorBlockOn for Rc<E>
84where
85 E: ExecutorBlockOn,
86{
87 fn block_on<F: Future>(&self, f: F) -> F::Output {
88 (**self).block_on(f)
89 }
90}