pub struct Timestamp(/* private fields */);Expand description
Wall-clock timestamp with monotonic guarantee within the system.
Compliance requires real-world time for audit trails; monotonicity prevents ordering issues when system clocks are adjusted.
Stored as nanoseconds since Unix epoch (1970-01-01 00:00:00 UTC). This gives us ~584 years of range, well beyond any practical use.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn from_nanos(nanos: u64) -> Self
pub fn from_nanos(nanos: u64) -> Self
Creates a timestamp from nanoseconds since Unix epoch.
Sourcepub fn as_secs(&self) -> u64
pub fn as_secs(&self) -> u64
Returns the timestamp as seconds since Unix epoch (truncates nanoseconds).
Sourcepub fn now() -> Self
pub fn now() -> Self
Creates a timestamp for the current time.
§Panics
Panics if the system clock is before Unix epoch (should never happen).
Sourcepub fn now_monotonic(last: Option<Timestamp>) -> Self
pub fn now_monotonic(last: Option<Timestamp>) -> Self
Creates a timestamp ensuring monotonicity: max(now, last + 1ns).
This guarantees that each timestamp is strictly greater than the previous, even if the system clock moves backwards or two events occur in the same nanosecond.
§Arguments
last- The previous timestamp, if any. PassNonefor the first timestamp.