1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::{future::Future, time::Duration};
use futures::Stream;
pub trait Runtime: Clone + Send + Sync {
type Instant: Copy + Send + Sync;
type Delay: Future<Output = ()> + Unpin + Send;
type Interval: Stream<Item = Self::Instant> + Unpin + Send;
fn spawn<F>(&self, future: F)
where
F: Future<Output = ()> + Send + 'static;
fn now(&self) -> Self::Instant;
fn elapsed(&self, instant: Self::Instant) -> Duration;
fn duration_between(&self, earlier: Self::Instant, later: Self::Instant) -> Duration;
fn delay(&self, duration: Duration) -> Self::Delay;
fn interval(&self, duration: Duration) -> Self::Interval;
}
impl<'a, R: Runtime> Runtime for &'a R {
type Instant = R::Instant;
type Delay = R::Delay;
type Interval = R::Interval;
fn spawn<F>(&self, future: F)
where
F: Future<Output = ()> + Send + 'static,
{
(**self).spawn(future);
}
fn now(&self) -> Self::Instant {
(**self).now()
}
fn elapsed(&self, instant: Self::Instant) -> Duration {
(**self).elapsed(instant)
}
fn duration_between(&self, earlier: Self::Instant, later: Self::Instant) -> Duration {
(**self).duration_between(earlier, later)
}
fn delay(&self, duration: Duration) -> Self::Delay {
(**self).delay(duration)
}
fn interval(&self, duration: Duration) -> Self::Interval {
(**self).interval(duration)
}
}