pub trait PlatformClock {
// Required methods
fn clock_ns() -> u64;
fn clock_resolution_ns() -> u64;
// Provided method
fn epoch_us() -> u64 { ... }
}Expand description
Monotonic clock.
The most critical platform primitive. Must be backed by a hardware timer or OS tick — never by a software counter that only advances when polled.
Required Methods§
Sourcefn clock_ns() -> u64
fn clock_ns() -> u64
Monotonic nanoseconds since a platform-defined epoch. Never
decreases. See <nros/platform.h> for the full contract
(RFC-0073).
Sourcefn clock_resolution_ns() -> u64
fn clock_resolution_ns() -> u64
Granularity of Self::clock_ns in nanoseconds: the smallest
non-zero difference two successive reads can report. Non-zero,
and constant after platform init.
Provided Methods§
Sourcefn epoch_us() -> u64
fn epoch_us() -> u64
Microseconds since the UNIX epoch, or 0 when this platform has no
wall-clock source. See <nros/platform.h> for the full contract
(issue 0758).
DEFAULTED to 0 deliberately. Every existing port is correct
without changing a line: none of them has an epoch source today, and
0 is precisely the honest answer. Making this a required method
would have forced eleven ports to write 0 by hand, which is the
same information spelled eleven times plus eleven chances to write
something else.
It is also the difference between an ABI addition that is a
no-op for ports and one that breaks every image that has not caught
up — and the C side has no such default, so a port implemented in C
DOES say 0 explicitly.
Unlike Self::clock_ns this is not monotonic: a port that
acquires its epoch after boot jumps when it does.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl PlatformClock for CffiPlatform
impl PlatformClock for CffiPlatform
Source§fn epoch_us() -> u64
fn epoch_us() -> u64
issue 0758 — forwards to the C symbol. NOT defaulted here: a C port
that supplies the symbol must be able to answer, and one that does
not returns 0 from its own definition. Taking the trait default
instead would silently ignore a C implementation that exists.