pub trait TimeServiceTrait: Send + Sync + Clone + Debug {
    // Required methods
    fn now(&self) -> Instant;
    fn now_unix_time(&self) -> Duration;
    fn sleep_blocking(&self, duration: Duration);

    // Provided method
    fn now_secs(&self) -> u64 { ... }
}

Required Methods§

source

fn now(&self) -> Instant

Query a monotonically nondecreasing clock. Returns an opaque type that can only be compared to other Instants, i.e., this is a monotonic relative time whereas now_unix_time is a non-monotonic absolute time.

On Linux, this is equivalent to clock_gettime(CLOCK_MONOTONIC, _)

See Instant for more details.

source

fn now_unix_time(&self) -> Duration

Query the current unix timestamp as a Duration.

When used on a TimeService::real(), this is equivalent to SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).

Note: the Duration returned from this function is NOT guaranteed to be monotonic. Use now if you need monotonicity.

From the SystemTime docs:

Distinct from the Instant type, this time measurement is not monotonic. This means that you can save a file to the file system, then save another file to the file system, and the second file has a SystemTime measurement earlier than the first. In other words, an operation that happens after another operation in real time may have an earlier SystemTime!

For example, the system administrator could clock_settime into the past, breaking clock time monotonicity.

On Linux, this is equivalent to clock_gettime(CLOCK_REALTIME, _).

source

fn sleep_blocking(&self, duration: Duration)

Blocks the current thread until duration time has passed.

Provided Methods§

source

fn now_secs(&self) -> u64

Query the current unix timestamp in seconds.

Equivalent to self.now_unix_time().as_secs(). See now_unix_time.

Object Safety§

This trait is not object safe.

Implementors§