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

source

pub fn checked_to_system_time(self) -> Option<SystemTime>

Return the SystemTime component, if one exists.

source

pub fn checked_to_instant(self) -> Option<Instant>

Return the Instant component, if one exists.

source

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)

source

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)

source

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.

source

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

An Add implementation for PartialComplexTime that adds the duration to each of the time values it holds.

§Panics

The Add implementations for both SystemTime and Instant, which this uses, will panic on overflow.

§

type Output = PartialComplexTime

The resulting type after applying the + operator.
source§

fn add(self, dur: Duration) -> Self

Performs the + operation. Read more
source§

impl AddAssign<Duration> for PartialComplexTime

AddAssign implementation that relies on the above Add implementation.

source§

fn add_assign(&mut self, other: Duration)

Performs the += operation. Read more
source§

impl Clone for PartialComplexTime

source§

fn clone(&self) -> PartialComplexTime

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PartialComplexTime

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<(SystemTime, Instant)> for PartialComplexTime

source§

fn from(t: (SystemTime, Instant)) -> PartialComplexTime

Converts to this type from the input type.
source§

impl From<ComplexTime> for PartialComplexTime

source§

fn from(t: ComplexTime) -> Self

Converts to this type from the input type.
source§

impl From<Instant> for PartialComplexTime

source§

fn from(m: Instant) -> PartialComplexTime

Converts to this type from the input type.
source§

impl From<SystemTime> for PartialComplexTime

source§

fn from(w: SystemTime) -> PartialComplexTime

Converts to this type from the input type.
source§

impl Hash for PartialComplexTime

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for PartialComplexTime

source§

fn eq(&self, other: &PartialComplexTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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.

§

type Output = PartialComplexTime

The resulting type after applying the - operator.
source§

fn sub(self, dur: Duration) -> Self

Performs the - operation. Read more
source§

impl SubAssign<Duration> for PartialComplexTime

SubAssign implementation that relies on the above Add implementation.

source§

fn sub_assign(&mut self, other: Duration)

Performs the -= operation. Read more
source§

impl Copy for PartialComplexTime

source§

impl Eq for PartialComplexTime

source§

impl StructuralPartialEq for PartialComplexTime

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Unless for T

source§

fn unless(self, option: Option<T>) -> T

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T, Rhs, Output> GroupOps<Rhs, Output> for T
where T: Add<Rhs, Output = Output> + Sub<Rhs, Output = Output> + AddAssign<Rhs> + SubAssign<Rhs>,