Skip to main content

Instant

Struct Instant 

pub struct Instant(/* private fields */);
Expand description

A point on the monotonic clock, in nanoseconds from the clock’s origin.

The methods mirror std::time::Instant’s, except that moving one by a Duration has no operator: each caller picks checked_ or saturating_, so a duration past the clock’s range is handled rather than panicking. The time between two instants (duration_since and -) saturates to zero when the later one comes first, as std’s does; checked_duration_since reports that case instead. Instants are only comparable within one clock: the simulator starts at Instant::ZERO, and the runtime backends count from an origin they pick once, reading far past zero there so earlier moments stay representable. Instant::into_std and Instant::from_std convert at a third-party API that takes std’s instants.

Implementations§

§

impl Instant

pub const ZERO: Instant

The clock’s origin.

pub fn now() -> Instant

The current instant on the ambient clock.

pub fn elapsed(&self) -> Duration

The time elapsed since this instant on the ambient clock, zero if it is in the future.

pub fn duration_since(&self, earlier: Instant) -> Duration

The time from earlier to this instant, zero if earlier is later.

pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>

The time from earlier to this instant, or None if earlier is later.

pub fn saturating_duration_since(&self, earlier: Instant) -> Duration

The time from earlier to this instant, zero if earlier is later.

pub fn checked_add(&self, duration: Duration) -> Option<Instant>

This instant moved forward by duration, or None past the clock’s range.

pub fn checked_sub(&self, duration: Duration) -> Option<Instant>

This instant moved back by duration, or None before the clock’s origin.

pub fn saturating_add(&self, duration: Duration) -> Instant

This instant moved forward by duration, stopping at the clock’s last instant.

pub fn saturating_sub(&self, duration: Duration) -> Instant

This instant moved back by duration, stopping at the clock’s origin.

pub fn into_std(self) -> Instant

This instant on std’s clock, for a third-party API that takes one.

Maps through the runtime backend’s origin, as its timers do. That is exact on a running clock. On paused tokio or the simulator it keeps the time between instants, but not their distance from std::time::Instant::now.

§Panics

When std’s clock cannot represent it, as with a simulated instant near zero on a platform whose std clock starts at boot.

pub fn from_std(at: Instant) -> Instant

The instant at names on std’s clock, the inverse of Instant::into_std.

Saturates at the clock’s range, like a deadline past it.

Trait Implementations§

§

impl Clone for Instant

§

fn clone(&self) -> Instant

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
§

impl Copy for Instant

§

impl Debug for Instant

§

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

Formats the value using the given formatter. Read more
§

impl Eq for Instant

Source§

impl From<Instant> for Timestamp

Source§

fn from(instant: Instant) -> Self

Convert an Instant into a millisecond-scale timestamp, measured from the model clock’s anchor.

One-way only: there is no inverse, since the anchor is jittered to keep a Timestamp from being read back as a clock.

§

impl Hash for Instant

§

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

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
§

impl Ord for Instant

§

fn cmp(&self, other: &Instant) -> 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§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
§

impl PartialEq for Instant

§

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

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

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

Inequality operator !=. Read more
§

impl PartialOrd for Instant

§

fn partial_cmp(&self, other: &Instant) -> 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
§

impl StructuralPartialEq for Instant

§

impl Sub for Instant

§

fn sub(self, earlier: Instant) -> Duration

The time from earlier to this instant, zero if earlier is later.

§

type Output = Duration

The resulting type after applying the - operator.

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> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, !>

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> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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