Struct otter_api_tests::time::SystemTime 1.8.0[−][src]
pub struct SystemTime(_);
Expand description
A measurement of the system clock, useful for talking to external entities like the file system or other processes.
Distinct from the Instant type, 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 a
SystemTime measurement earlier than the first. In other words, an
operation that happens after another operation in real time may have an
earlier SystemTime!
Consequently, comparing two SystemTime instances to learn about the
duration between them returns a Result instead of an infallible Duration
to indicate that this sort of time drift may happen and needs to be handled.
Although a SystemTime cannot be directly inspected, the UNIX_EPOCH
constant is provided in this module as an anchor in time to learn
information about a SystemTime. By calculating the duration from this
fixed point in time, a SystemTime can be converted to a human-readable time,
or perhaps some other string representation.
The size of a SystemTime struct may vary depending on the target operating
system.
Example:
use std::time::{Duration, SystemTime}; use std::thread::sleep; fn main() { let now = SystemTime::now(); // we sleep for 2 seconds sleep(Duration::new(2, 0)); match now.elapsed() { Ok(elapsed) => { // it prints '2' println!("{}", elapsed.as_secs()); } Err(e) => { // an error occurred! println!("Error: {:?}", e); } } }
Underlying System calls
Currently, the following system calls are being used to get the current time using now():
| Platform | System call |
|---|---|
| SGX | insecure_time usercall. More information on timekeeping in SGX |
| UNIX | clock_gettime (Realtime Clock) |
| Darwin | gettimeofday |
| VXWorks | clock_gettime (Realtime Clock) |
| WASI | __wasi_clock_time_get (Realtime Clock) |
| Windows | GetSystemTimePreciseAsFileTime / GetSystemTimeAsFileTime |
Disclaimer: These system calls might change over time.
Note: mathematical operations like
addmay panic if the underlying structure cannot represent the new point in time.
Implementations
An anchor in time which can be used to create new SystemTime instances or
learn about where in time a SystemTime lies.
This constant is defined to be “1970-01-01 00:00:00 UTC” on all systems with
respect to the system clock. Using duration_since on an existing
SystemTime instance can tell how far away from this point in time a
measurement lies, and using UNIX_EPOCH + duration can be used to create a
SystemTime instance to represent another fixed point in time.
Examples
use std::time::SystemTime; match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()), Err(_) => panic!("SystemTime before UNIX EPOCH!"), }
Returns the system time corresponding to “now”.
Examples
use std::time::SystemTime; let sys_time = SystemTime::now();
Returns the amount of time elapsed from an earlier point in time.
This function may fail because measurements taken earlier are not
guaranteed to always be before later measurements (due to anomalies such
as the system clock being adjusted either forwards or backwards).
Instant can be used to measure elapsed time without this risk of failure.
If successful, Ok(Duration) is returned where the duration represents
the amount of time elapsed from the specified measurement to this one.
Returns an Err if earlier is later than self, and the error
contains how far from self the time is.
Examples
use std::time::SystemTime; let sys_time = SystemTime::now(); let new_sys_time = SystemTime::now(); let difference = new_sys_time.duration_since(sys_time) .expect("Clock may have gone backwards"); println!("{:?}", difference);
Returns the difference between the clock time when this system time was created, and the current clock time.
This function may fail as the underlying system clock is susceptible to
drift and updates (e.g., the system clock could go backwards), so this
function may not always succeed. If successful, Ok(Duration) is
returned where the duration represents the amount of time elapsed from
this time measurement to the current time.
To measure elapsed time reliably, use Instant instead.
Returns an Err if self is later than the current system time, and
the error contains how far from the current system time self is.
Examples
use std::thread::sleep; use std::time::{Duration, SystemTime}; let sys_time = SystemTime::now(); let one_sec = Duration::from_secs(1); sleep(one_sec); assert!(sys_time.elapsed().unwrap() >= one_sec);
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.
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.
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.
type Output = SystemTime
type Output = SystemTimeThe resulting type after applying the + operator.
Performs the += operation. Read more
Performs the conversion.
pub fn deserialize<D>(
deserializer: D
) -> Result<SystemTime, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
pub fn deserialize<D>(
deserializer: D
) -> Result<SystemTime, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>, Deserialize this value from the given Serde deserializer. Read more
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
impl From<SystemTime> for FileTime
impl From<SystemTime> for FileTimepub fn from(time: SystemTime) -> FileTime
pub fn from(time: SystemTime) -> FileTimePerforms the conversion.
Performs the conversion.
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
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
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer, Serialize this value into the given Serde serializer. Read more
type Output = SystemTime
type Output = SystemTimeThe resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Auto Trait Implementations
impl RefUnwindSafe for SystemTimeimpl Send for SystemTimeimpl Sync for SystemTimeimpl Unpin for SystemTimeimpl UnwindSafe for SystemTimeBlanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
A: Allocator,
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s. Read more
impl<A> DynCastExt for A
impl<A> DynCastExt for Apub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>,
pub fn dyn_cast<T>(
self
) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source> where
T: ?Sized,
A: DynCastExtHelper<T>, Use this to cast from one trait object type to another. Read more
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>,
pub fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target where
T: ?Sized,
A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>, Use this to upcast a trait to one of its supertraits. Read more
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
F: ?Sized,
pub fn dyn_cast_adv<F, T>(
self
) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source> where
T: ?Sized,
A: DynCastExtAdvHelper<F, T>,
F: ?Sized, pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>,
pub fn dyn_cast_with_config<C>(
self
) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source> where
C: DynCastConfig,
A: DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>, Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
Compare self to key and return true if they are equal.
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;pub fn vzip(self) -> V