pub trait SystemTimeExt {
// Required methods
fn epoch(&self) -> Duration;
fn epoch_millis(&self) -> u64;
fn add_jittered(&self, rng: &mut impl Rng, jitter: Duration) -> SystemTime;
}
Expand description
Extension trait to add methods to std::time::SystemTime
Required Methods§
Sourcefn epoch(&self) -> Duration
fn epoch(&self) -> Duration
Returns the duration since the Unix epoch.
Panics if the system time is before the Unix epoch.
Sourcefn epoch_millis(&self) -> u64
fn epoch_millis(&self) -> u64
Returns the number of milliseconds (rounded down) since the Unix epoch.
Panics if the system time is before the Unix epoch.
Saturates at u64::MAX
.
Sourcefn add_jittered(&self, rng: &mut impl Rng, jitter: Duration) -> SystemTime
fn add_jittered(&self, rng: &mut impl Rng, jitter: Duration) -> SystemTime
Adds a random Duration
to the current time between 0
and jitter * 2
and returns the
resulting SystemTime
. The random duration is generated using the provided context
.
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.