pub enum PartialComplexTime {
Wall(SystemTime),
Monotonic(Instant),
Complex(ComplexTime),
}
Expand description
PartialComplexTime
provides a std::interator::EitherOrBoth
-like type which is specifically
for holding either one, or both, of the time types that make up a ComplexTime
. It’s a type
that holds a value for at least one of the timelines.
The important differentiation of this vs. a struct such as:
use std::time::SystemTime;
struct MaybeBoth {
wall: Option<SystemTime>,
monotonic: Option<SystemTime>
}
is that there is no valid (None, None)
state for this type to be in, and so code that uses can
be certain that some time is specified.
Like ComplexTime
, PartialComplexTime
implements all the standard math operations in
std::ops
that are implemented for both std::time::SystemTime
and std::time:Instant
. Like
those implementations, they will panic on overflow.
Variants§
Wall(SystemTime)
Just a wall time.
Monotonic(Instant)
Just a monotonic time.
Complex(ComplexTime)
Both a wall and a monotonic time.
Implementations§
Source§impl PartialComplexTime
impl PartialComplexTime
Sourcepub fn checked_to_system_time(self) -> Option<SystemTime>
pub fn checked_to_system_time(self) -> Option<SystemTime>
Return the SystemTime component, if one exists.
Sourcepub fn checked_to_instant(self) -> Option<Instant>
pub fn checked_to_instant(self) -> Option<Instant>
Return the Instant component, if one exists.
Sourcepub fn checked_to_micros_since_epoch(self) -> Option<i64>
pub fn checked_to_micros_since_epoch(self) -> Option<i64>
Convert the SystemTime component of this PartialComplexTime into i64 microseconds from the UNIX Epoch. Provides coverage over +/- approx 30,000 years from 1970-01-01 UTC.
Returns None if it doesn’t have a wall time or on overflow (instead of panicking)
Sourcepub fn from_micros_since_epoch(micros: i64) -> Self
pub fn from_micros_since_epoch(micros: i64) -> Self
Return the PartialComplexTime::Wall that represents the same time as the specified microseconds from the UNIX Epoch (1970-01-01 UTC)
Sourcepub fn complete_with(&self, complex: ComplexTime) -> ComplexTime
pub fn complete_with(&self, complex: ComplexTime) -> ComplexTime
Return a new ComplexTime that’s based on the time values of this PartialComplexTime, setting either unknown field from the passed-in ComplexTime.
Sourcepub fn destructure(&self) -> (Option<SystemTime>, Option<Instant>)
pub fn destructure(&self) -> (Option<SystemTime>, Option<Instant>)
Destructure the PartialComplexTime into it’s two components, each as an Option.
Trait Implementations§
Source§impl Add<Duration> for PartialComplexTime
impl Add<Duration> for PartialComplexTime
An Add
implementation for PartialComplexTime that adds the duration to each of the time
values it holds.
§Panics
The Add
Source§impl AddAssign<Duration> for PartialComplexTime
impl AddAssign<Duration> for PartialComplexTime
AddAssign implementation that relies on the above Add implementation.
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
+=
operation. Read moreSource§impl Clone for PartialComplexTime
impl Clone for PartialComplexTime
Source§fn clone(&self) -> PartialComplexTime
fn clone(&self) -> PartialComplexTime
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for PartialComplexTime
impl Debug for PartialComplexTime
Source§impl Display for PartialComplexTime
impl Display for PartialComplexTime
PartialComplexTime
implements Display
to provide a human-readable, detailed, format for
its values. It uses the ReadableSystemTime
struct for its SystemTime
component, and the
Debug
trait implementation of Instant
, as that type’s internals are not accessible, and
it only implements Debug
.
§Example
use std::time::{Duration, Instant, SystemTime};
use omaha_client::time::{ComplexTime, PartialComplexTime};
assert_eq!(
format!("{}", PartialComplexTime::Complex(ComplexTime{
wall: SystemTime::UNIX_EPOCH + Duration::from_nanos(994610096026420000),
mono: Instant::now()
})),
"2001-07-08 16:34:56.026 UTC (994610096.026420000) and Instant{ tv_sec: SEC, tv_nsec: NSEC }"
);
assert_eq!(
format!("{}", PartialComplexTime::Wall(
SystemTime::UNIX_EPOCH + Duration::from_nanos(994610096026420000),
)),
"2001-07-08 16:34:56.026 UTC (994610096.026420000) and Instant{ tv_sec: SEC, tv_nsec: NSEC }"
);
assert_eq!(
format!("{}", PartialComplexTime::Monotonic(Instant::now())),
"2001-07-08 16:34:56.026 UTC (994610096.026420000) and Instant{ tv_sec: SEC, tv_nsec: NSEC }"
);
Source§impl From<(SystemTime, Instant)> for PartialComplexTime
impl From<(SystemTime, Instant)> for PartialComplexTime
Source§fn from(t: (SystemTime, Instant)) -> PartialComplexTime
fn from(t: (SystemTime, Instant)) -> PartialComplexTime
Source§impl From<ComplexTime> for PartialComplexTime
impl From<ComplexTime> for PartialComplexTime
Source§fn from(t: ComplexTime) -> Self
fn from(t: ComplexTime) -> Self
Source§impl From<Instant> for PartialComplexTime
impl From<Instant> for PartialComplexTime
Source§fn from(m: Instant) -> PartialComplexTime
fn from(m: Instant) -> PartialComplexTime
Source§impl From<SystemTime> for PartialComplexTime
impl From<SystemTime> for PartialComplexTime
Source§fn from(w: SystemTime) -> PartialComplexTime
fn from(w: SystemTime) -> PartialComplexTime
Source§impl Hash for PartialComplexTime
impl Hash for PartialComplexTime
Source§impl PartialEq for PartialComplexTime
impl PartialEq for PartialComplexTime
Source§impl Sub<Duration> for PartialComplexTime
impl Sub<Duration> for PartialComplexTime
A Sub
implementation for PartialComplexTime that subtracts the duration to each of the time
values it holds.
§Panics
Panics when the result cannot be expressed in the underlying representation. Specifically, SystemTime, Instant, and ComplexTime may not be able to represent the resulting time.
Source§impl SubAssign<Duration> for PartialComplexTime
impl SubAssign<Duration> for PartialComplexTime
SubAssign implementation that relies on the above Add implementation.
Source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
-=
operation. Read moreimpl Copy for PartialComplexTime
impl Eq for PartialComplexTime
impl StructuralPartialEq for PartialComplexTime
Auto Trait Implementations§
impl Freeze for PartialComplexTime
impl RefUnwindSafe for PartialComplexTime
impl Send for PartialComplexTime
impl Sync for PartialComplexTime
impl Unpin for PartialComplexTime
impl UnwindSafe for PartialComplexTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)