pub struct SystemTime { /* private fields */ }
Expand description

A measurement of the system clock, useful for talking to external entities like the file system or other processes.

This corresponds to std::time::SystemTime.

This SystemTime has no now, elapsed methods. To obtain the current time or measure the duration to the current time, first obtain a SystemClock, and then call SystemClock::now or SystemClock::elapsed instead. The UNIX_EPOCH constant is at SystemClock::UNIX_EPOCH.

Similar to the filetime crate, when RUSTFLAGS=--cfg emulate_second_only_system is set, SystemTime will round times from the operating system down to the second. This emulates the behavior of some file systems, mostly HFS, allowing debugging on other hardware.

Implementations§

Constructs a new instance of Self from the given std::time::SystemTime.

Examples found in repository?
src/time/system_clock.rs (line 38)
37
38
39
    pub fn now(&self) -> SystemTime {
        SystemTime::from_std(time::SystemTime::now())
    }
More examples
Hide additional examples
src/fs/system_time_spec.rs (line 24)
20
21
22
23
24
25
26
27
    pub fn from_std(std: fs_set_times::SystemTimeSpec) -> Self {
        match std {
            fs_set_times::SystemTimeSpec::SymbolicNow => Self::SymbolicNow,
            fs_set_times::SystemTimeSpec::Absolute(time) => {
                Self::Absolute(SystemTime::from_std(time))
            }
        }
    }

Constructs a new instance of std::time::SystemTime from the given Self.

Examples found in repository?
src/fs/system_time_spec.rs (line 35)
32
33
34
35
36
37
    pub const fn into_std(self) -> fs_set_times::SystemTimeSpec {
        match self {
            Self::SymbolicNow => fs_set_times::SystemTimeSpec::SymbolicNow,
            Self::Absolute(time) => fs_set_times::SystemTimeSpec::Absolute(time.into_std()),
        }
    }

Returns the amount of time elapsed from another instant to this one.

This corresponds to std::time::SystemTime::duration_since.

Returns Some(t) where t is the time self + duration if t can be represented as SystemTime (which means it’s inside the bounds of the underlying data structure), None otherwise.

This corresponds to std::time::SystemTime::checked_add.

Examples found in repository?
src/time/system_time.rs (line 96)
95
96
97
98
    fn add(self, dur: Duration) -> Self {
        self.checked_add(dur)
            .expect("overflow when adding duration to instant")
    }

Returns Some(t) where t is the time self - duration if t can be represented as SystemTime (which means it’s inside the bounds of the underlying data structure), None otherwise.

This corresponds to std::time::SystemTime::checked_sub.

Examples found in repository?
src/time/system_time.rs (line 113)
112
113
114
115
    fn sub(self, dur: Duration) -> Self {
        self.checked_sub(dur)
            .expect("overflow when subtracting duration from instant")
    }

Trait Implementations§

Panics

This function may panic if the resulting point in time cannot be represented by the underlying data structure. See SystemTime::checked_add for a version without panic.

The resulting type after applying the + operator.
Performs the += operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.