Skip to main content

tokio/runtime/metrics/
schedule_latency_mock.rs

1//! A mock implementation of the types in `schedule_latency`. These types
2//! are zero-sized so that the size of types using them are not increased
3//! unless schedule latency tracking is explicitly enabled.
4
5use std::time::Instant;
6
7#[derive(Copy, Clone)]
8pub(crate) struct ScheduleLatencyInstant();
9
10impl ScheduleLatencyInstant {
11    pub(crate) fn new(_runtime_start: Option<Instant>) -> Self {
12        Self()
13    }
14
15    pub(crate) fn prepare(self, _runtime_start: Option<Instant>) -> Option<ScheduleLatencyContext> {
16        None
17    }
18}
19
20pub(crate) struct ScheduleLatencyContext {
21    _private: (),
22}
23
24impl ScheduleLatencyContext {
25    // This method is referenced (but never called) when the `schedule-latency`
26    // feature is disabled and `tokio_unstable` is enabled.
27    #[allow(dead_code)]
28    pub(crate) fn elapsed_nanos(&self, _now: Instant) -> u64 {
29        unimplemented!("This should never be called because prepare() always returns None")
30    }
31}