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
impl MonotonicInstant
Sourcepub const fn new(domain: ClockDomain, elapsed: Duration) -> Self
pub const fn new(domain: ClockDomain, elapsed: Duration) -> Self
Sourcepub const fn domain(self) -> ClockDomain
pub const fn domain(self) -> ClockDomain
Returns the identifier of the originating monotonic clock domain.
§Returns
The domain carried by this instant.
Sourcepub const fn elapsed_since_origin(self) -> Duration
pub const fn elapsed_since_origin(self) -> Duration
Sourcepub fn checked_add(self, duration: Duration) -> Result<Self, TimeError>
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.
Sourcepub fn duration_since(self, earlier: Self) -> Result<Duration, TimeError>
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.
Sourcepub fn validate_domain(
self,
expected_domain: ClockDomain,
) -> Result<(), TimeError>
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
impl Clone for MonotonicInstant
Source§fn clone(&self) -> MonotonicInstant
fn clone(&self) -> MonotonicInstant
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more