Skip to main content

MonotonicInstant

Struct MonotonicInstant 

Source
pub struct MonotonicInstant { /* private fields */ }
Expand description

A fixed point in one monotonic clock domain.

Instants from different domains cannot be ordered or used in arithmetic together. The value carries the full precision available through Duration without claiming any particular hardware timer resolution.

Discarding a sampled instant is rejected when unused_must_use is denied:

#![deny(unused_must_use)]
use qubit_clock::{ManualMonotonicClock, MonotonicClock};

ManualMonotonicClock::new().now();

Implementations§

Source§

impl MonotonicInstant

Source

pub const fn new(domain: ClockDomain, elapsed: Duration) -> Self

Creates an instant for a clock implementation.

§Parameters
  • domain - Identifier of the originating clock.
  • elapsed - Duration measured from that clock’s private origin.
§Returns

An instant scoped to domain at elapsed.

Source

pub const fn domain(self) -> ClockDomain

Returns the identifier of the originating monotonic clock domain.

§Returns

The domain carried by this instant.

Source

pub const fn elapsed_since_origin(self) -> Duration

Returns the elapsed duration from this clock domain’s origin.

The value is meaningful only inside the domain identified by domain().

§Returns

The duration from the originating clock’s private origin.

Source

pub fn checked_add(self, duration: Duration) -> Result<Self, TimeError>

Adds a duration while preserving the originating clock domain.

Returns TimeError::InstantOverflow when the result cannot be represented by Duration.

§Parameters
  • duration - Duration to add to this instant.
§Returns

A same-domain instant advanced by duration.

§Errors

Returns TimeError::InstantOverflow when the elapsed duration cannot represent the result.

Source

pub fn duration_since(self, earlier: Self) -> Result<Duration, TimeError>

Calculates the duration elapsed since an earlier instant.

Returns TimeError::ClockDomainMismatch when earlier belongs to a different clock, and TimeError::InvalidInstantOrder when earlier is later than this instant.

§Parameters
  • earlier - Earlier instant expected to belong to the same domain.
§Returns

The elapsed duration from earlier to this instant.

§Errors

Returns TimeError::ClockDomainMismatch for a foreign instant. Returns TimeError::InvalidInstantOrder when earlier is later, retaining both elapsed durations.

Source

pub fn validate_domain( self, expected_domain: ClockDomain, ) -> Result<(), TimeError>

Verifies that this instant belongs to expected_domain.

Custom monotonic clocks and timers can use this method to reject externally supplied instants before performing domain-specific work.

§Parameters
  • expected_domain - Domain the instant must belong to.
§Returns

Ok(()) when the domains match.

§Errors

Returns TimeError::ClockDomainMismatch when the domains differ.

Trait Implementations§

Source§

impl Clone for MonotonicInstant

Source§

fn clone(&self) -> MonotonicInstant

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 MonotonicInstant

Source§

impl Debug for MonotonicInstant

Source§

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

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

impl Eq for MonotonicInstant

Source§

impl Hash for MonotonicInstant

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 MonotonicInstant

Source§

fn eq(&self, other: &MonotonicInstant) -> 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 MonotonicInstant

Source§

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

Orders two instants only when they belong to the same clock domain.

§Parameters
  • other - Instant to compare with this one.
§Returns

Their elapsed-time ordering for a shared domain, or None for distinct domains.

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 MonotonicInstant

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

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 = !

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.