Skip to main content

dope_fiber/task/time/
clock.rs

1//! Zero-state projection of the current fiber poll's driver clock.
2
3use std::task;
4
5use crate::{abi, context, core::driver::schedule::clock};
6
7/// Clock projection constructors for the active driver turn.
8pub enum Clock {}
9
10impl Clock {
11    pub const fn now() -> Now {
12        Now
13    }
14}
15
16/// A zero-sized, one-poll clock projection. It uses no TLS, allocation, wake
17/// slot, or scheduler credit beyond the poll which already executes it.
18#[must_use = "a clock projection does nothing unless it is driven"]
19pub struct Now;
20
21impl<'d> abi::Fiber<'d> for Now {
22    type Output = clock::Moment<'d>;
23
24    fn poll(call: context::PollCall<'_, '_, 'd, Self>) -> task::Poll<Self::Output> {
25        let mut context = call.into_context();
26        task::Poll::Ready(context.as_mut().driver().driver_ref().clock().now())
27    }
28}
29
30const _: () = assert!(std::mem::size_of::<Now>() == 0);