pub struct Now {
pub monotonic_ms: u64,
pub unix_seconds: Option<u64>,
}Expand description
A single time sample handed to caller-driven components.
Hosts take one sample per drive iteration and pass the same value to every agent, transport, and runtime they poll, so all of them observe a consistent “now”.
§Monotonic time
monotonic_ms counts milliseconds from an epoch
chosen by the Clock that produced it. The epoch is arbitrary and carries
no meaning across clocks: only differences between samples from the same
clock are meaningful. Samples from one clock never decrease, and never
exceed MAX_MONOTONIC_MS.
§Wall-clock time
unix_seconds is None when the platform offers no
usable wall-clock reading: it has no wall-clock source at all, such as an
embedded board without an RTC or NTP sync, or its source currently reads
before the Unix epoch. Components that need real time (signed beacon
freshness, certificate validity) must handle its absence explicitly rather
than substituting monotonic time, which is not comparable across peers.
Fields§
§monotonic_ms: u64Milliseconds since this clock’s arbitrary epoch. Never decreases, and
never exceeds MAX_MONOTONIC_MS.
unix_seconds: Option<u64>Seconds since the Unix epoch, or None if the platform has no usable
wall-clock reading.
Implementations§
Source§impl Now
impl Now
Sourcepub const MAX_MONOTONIC_MS: u64
pub const MAX_MONOTONIC_MS: u64
The largest monotonic value a clock may report.
u64::MAX is reserved as the end of the timeline: it is the value
Deadline::NEVER occupies, so an instant there could not be expressed
as a deadline that is due. Clocks saturate here instead, which at
millisecond resolution costs one millisecond after ~584 million years of
uptime.
Sourcepub const fn from_millis(monotonic_ms: u64) -> Self
pub const fn from_millis(monotonic_ms: u64) -> Self
Creates a sample with monotonic time only and no wall clock.
Sourcepub const fn new(monotonic_ms: u64, unix_seconds: u64) -> Self
pub const fn new(monotonic_ms: u64, unix_seconds: u64) -> Self
Creates a sample carrying both monotonic and wall-clock time.
Sourcepub const fn with_unix_seconds(self, unix_seconds: u64) -> Self
pub const fn with_unix_seconds(self, unix_seconds: u64) -> Self
Returns this sample with the given wall-clock time attached.
Sourcepub const fn saturating_millis_since(self, earlier: Self) -> u64
pub const fn saturating_millis_since(self, earlier: Self) -> u64
Returns the milliseconds elapsed since earlier, saturating at zero.
Both samples must come from the same clock; comparing across clocks is meaningless because their epochs are unrelated.
Sourcepub const fn deadline_after(self, millis: u64) -> Deadline
pub const fn deadline_after(self, millis: u64) -> Deadline
Returns a deadline millis in the future, saturating at
Deadline::NEVER.
Sourcepub const fn as_deadline(self) -> Deadline
pub const fn as_deadline(self) -> Deadline
Returns the deadline that expires exactly at this sample, so it is due
as of self.
Samples respecting MAX_MONOTONIC_MS always
convert; the reserved u64::MAX is the one value that cannot, and
yields Deadline::NEVER.