omaha_client::time

Enum PartialComplexTime

Source
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.

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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.

Source§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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>,