pi_async_executor/
clock.rs1use pi_clock_manual::global::GlobalManualInstant;
3use std::time::Duration;
4
5pub trait ExecutorClock: Clone + Send + Sync + 'static {
10 type Instant: Send + 'static;
12 fn now(&self) -> pi_result::Result<Self::Instant>;
14 fn checked_add(
16 &self,
17 now: &Self::Instant,
18 duration: Duration,
19 ) -> pi_result::Result<Self::Instant>;
20 fn remaining(
23 &self,
24 now: &Self::Instant,
25 deadline: &Self::Instant,
26 ) -> pi_result::Result<Duration>;
27}
28
29#[derive(Clone, Copy, Debug)]
36pub struct ManualClock;
37impl ManualClock {
38 pub fn new() -> pi_result::Result<Self> {
40 manual_clock_new_inner()
41 }
42}
43impl ExecutorClock for ManualClock {
44 type Instant = GlobalManualInstant;
45 fn now(&self) -> pi_result::Result<Self::Instant> {
46 manual_clock_now_inner(self)
47 }
48 fn checked_add(
49 &self,
50 now: &Self::Instant,
51 duration: Duration,
52 ) -> pi_result::Result<Self::Instant> {
53 manual_clock_add_inner(self, now, duration)
54 }
55 fn remaining(
56 &self,
57 now: &Self::Instant,
58 deadline: &Self::Instant,
59 ) -> pi_result::Result<Duration> {
60 manual_clock_remaining_inner(self, now, deadline)
61 }
62}
63include!("clock_inner.rs");