Trait SystemTimeExt

Source
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§

Source

fn epoch(&self) -> Duration

Returns the duration since the Unix epoch.

Panics if the system time is before the Unix epoch.

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

impl SystemTimeExt for SystemTime

Source§

fn epoch(&self) -> Duration

Source§

fn epoch_millis(&self) -> u64

Source§

fn add_jittered(&self, rng: &mut impl Rng, jitter: Duration) -> SystemTime

Implementors§