pub struct Instant(/* private fields */);Available on crate feature
time only.Expand description
A monotonic instant represented as nanoseconds since an arbitrary origin.
This type is intentionally small and no_std friendly. It is suitable for:
- deadlines (
Deadline) - timeouts and elapsed-time calculations
- deterministic replay (when driven by a virtual clock)
Implementations§
Source§impl Instant
impl Instant
Sourcepub const fn from_nanos(nanos: u64) -> Self
pub const fn from_nanos(nanos: u64) -> Self
Creates an Instant from a nanosecond counter.
Sourcepub const fn as_nanos(self) -> u64
pub const fn as_nanos(self) -> u64
Returns this instant as nanoseconds since an arbitrary origin.
Sourcepub const fn checked_duration_since(self, earlier: Self) -> Option<Duration>
pub const fn checked_duration_since(self, earlier: Self) -> Option<Duration>
Returns the duration between earlier and self, if self >= earlier.
Sourcepub fn checked_add(self, duration: Duration) -> Option<Self>
pub fn checked_add(self, duration: Duration) -> Option<Self>
Returns the result of adding duration to this instant, or None on overflow.
Sourcepub fn checked_sub(self, duration: Duration) -> Option<Self>
pub fn checked_sub(self, duration: Duration) -> Option<Self>
Returns the result of subtracting duration from this instant, or None on underflow.
Trait Implementations§
Source§impl Ord for Instant
impl Ord for Instant
Source§impl PartialOrd for Instant
impl PartialOrd for Instant
impl Copy for Instant
impl Eq for Instant
impl StructuralPartialEq for Instant
Auto Trait Implementations§
impl Freeze for Instant
impl RefUnwindSafe for Instant
impl Send for Instant
impl Sync for Instant
impl Unpin for Instant
impl UnsafeUnpin for Instant
impl UnwindSafe for Instant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more