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§
Sourcefn now(&self) -> Instant
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.
Sourcefn now_unix_time(&self) -> Duration
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
Instanttype, 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 aSystemTimemeasurement 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, _).
Sourcefn sleep_blocking(&self, duration: Duration)
fn sleep_blocking(&self, duration: Duration)
Blocks the current thread until duration time has passed.
Provided Methods§
Sourcefn now_secs(&self) -> u64
fn now_secs(&self) -> u64
Query the current unix timestamp in seconds.
Equivalent to self.now_unix_time().as_secs().
See now_unix_time.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.