Skip to main content

Now

Struct Now 

Source
pub struct Now {
    pub monotonic_ms: u64,
    pub unix_seconds: Option<u64>,
}
Expand description

A single time sample handed to caller-driven components.

Hosts take one sample per drive iteration and pass the same value to every agent, transport, and runtime they poll, so all of them observe a consistent “now”.

§Monotonic time

monotonic_ms counts milliseconds from an epoch chosen by the Clock that produced it. The epoch is arbitrary and carries no meaning across clocks: only differences between samples from the same clock are meaningful. Samples from one clock never decrease, and never exceed MAX_MONOTONIC_MS.

§Wall-clock time

unix_seconds is None when the platform offers no usable wall-clock reading: it has no wall-clock source at all, such as an embedded board without an RTC or NTP sync, or its source currently reads before the Unix epoch. Components that need real time (signed beacon freshness, certificate validity) must handle its absence explicitly rather than substituting monotonic time, which is not comparable across peers.

Fields§

§monotonic_ms: u64

Milliseconds since this clock’s arbitrary epoch. Never decreases, and never exceeds MAX_MONOTONIC_MS.

§unix_seconds: Option<u64>

Seconds since the Unix epoch, or None if the platform has no usable wall-clock reading.

Implementations§

Source§

impl Now

Source

pub const MAX_MONOTONIC_MS: u64

The largest monotonic value a clock may report.

u64::MAX is reserved as the end of the timeline: it is the value Deadline::NEVER occupies, so an instant there could not be expressed as a deadline that is due. Clocks saturate here instead, which at millisecond resolution costs one millisecond after ~584 million years of uptime.

Source

pub const fn from_millis(monotonic_ms: u64) -> Self

Creates a sample with monotonic time only and no wall clock.

Source

pub const fn new(monotonic_ms: u64, unix_seconds: u64) -> Self

Creates a sample carrying both monotonic and wall-clock time.

Source

pub const fn with_unix_seconds(self, unix_seconds: u64) -> Self

Returns this sample with the given wall-clock time attached.

Source

pub const fn saturating_millis_since(self, earlier: Self) -> u64

Returns the milliseconds elapsed since earlier, saturating at zero.

Both samples must come from the same clock; comparing across clocks is meaningless because their epochs are unrelated.

Source

pub const fn deadline_after(self, millis: u64) -> Deadline

Returns a deadline millis in the future, saturating at Deadline::NEVER.

Source

pub const fn as_deadline(self) -> Deadline

Returns the deadline that expires exactly at this sample, so it is due as of self.

Samples respecting MAX_MONOTONIC_MS always convert; the reserved u64::MAX is the one value that cannot, and yields Deadline::NEVER.

Trait Implementations§

Source§

impl Clone for Now

Source§

fn clone(&self) -> Now

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Now

Source§

impl Debug for Now

Source§

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

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

impl Eq for Now

Source§

impl Hash for Now

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 Ord for Now

Source§

fn cmp(&self, other: &Now) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Now

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Now

Source§

fn partial_cmp(&self, other: &Now) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Now

Auto Trait Implementations§

§

impl Freeze for Now

§

impl RefUnwindSafe for Now

§

impl Send for Now

§

impl Sync for Now

§

impl Unpin for Now

§

impl UnsafeUnpin for Now

§

impl UnwindSafe for Now

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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