#[repr(C)]pub struct TimeSpec {
pub tv_sec: i64,
pub tv_nsec: i64,
}Expand description
POSIX-style timestamp: seconds + nanoseconds.
Used for SYS_CLOCK_GETTIME, SYS_NANOSLEEP, and file timestamps.
Fields§
§tv_sec: i64Seconds since Unix epoch (or relative time for sleep).
tv_nsec: i64Nanoseconds (0..999_999_999).
Implementations§
Source§impl TimeSpec
impl TimeSpec
Sourcepub fn to_nanos(&self) -> u64
pub fn to_nanos(&self) -> u64
Convert the timestamp to nanoseconds with saturating arithmetic.
A timestamp with any negative component is invalid as a duration
and yields 0: components previously cast individually into u64,
so a userspace-supplied negative nanosleep wrapped into a
near-infinite sleep. Callers that must reject invalid durations
should use TimeSpec::checked_to_nanos instead.
Sourcepub fn checked_to_nanos(&self) -> Option<u64>
pub fn checked_to_nanos(&self) -> Option<u64>
Convert to nanoseconds, returning None when any component is
negative (instead of silently clamping like TimeSpec::to_nanos).
Use this in paths that must surface EINVAL on invalid input.
Sourcepub fn from_nanos(nanos: u64) -> Self
pub fn from_nanos(nanos: u64) -> Self
Build a timestamp from a nanoseconds value.