SystemTimeExt

Trait SystemTimeExt 

Source
pub trait SystemTimeExt: Sealed {
    // Required methods
    fn checked_add_signed(&self, duration: Duration) -> Option<Self>;
    fn checked_sub_signed(&self, duration: Duration) -> Option<Self>;
    fn signed_duration_since(&self, earlier: Self) -> Duration;
}
Available on crate feature std only.
Expand description

An extension trait for std::time::SystemTime that adds methods for time::Durations.

Required Methods§

Source

fn checked_add_signed(&self, duration: Duration) -> Option<Self>

Adds the given Duration to the SystemTime, returning None is the result cannot be represented by the underlying data structure.

Source

fn checked_sub_signed(&self, duration: Duration) -> Option<Self>

Subtracts the given Duration from the SystemTime, returning None is the result cannot be represented by the underlying data structure.

Source

fn signed_duration_since(&self, earlier: Self) -> Duration

Returns the amount of time elapsed from another SystemTime to this one. This will be negative if earlier is later than self.

If the duration cannot be stored by Duration, the value will be saturated to Duration::MIN or Duration::MAX as appropriate.

§Example
let epoch = SystemTime::UNIX_EPOCH;
let other = epoch + 1.seconds();
assert_eq!(other.signed_duration_since(epoch), 1.seconds());
assert_eq!(epoch.signed_duration_since(other), (-1).seconds());

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 checked_add_signed(&self, duration: Duration) -> Option<Self>

Source§

fn checked_sub_signed(&self, duration: Duration) -> Option<Self>

Source§

fn signed_duration_since(&self, earlier: Self) -> Duration

Implementors§