pub struct AtomicInstant(/* private fields */);Available on crate feature
std only.Expand description
A monotonic instant stored in a single AtomicU64 as nanoseconds since a
shared process epoch (see now_monotonic_nanos).
Lock-free to read and update, useful for recency tracking (e.g. “least
recently used”) without a Mutex<Instant>. Reads/writes use relaxed
ordering, so it is a heuristic timestamp, not a synchronization point.
Implementations§
Source§impl AtomicInstant
impl AtomicInstant
Sourcepub fn now() -> Self
pub fn now() -> Self
Create an AtomicInstant set to now.
Sourcepub fn as_nanos(&self) -> u64
pub fn as_nanos(&self) -> u64
Nanoseconds since the shared epoch, for cheap ordering comparisons.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Duration elapsed since this instant (zero if it is in the future).
Sourcepub fn to_instant(&self) -> Instant
pub fn to_instant(&self) -> Instant
Convert back to a real Instant.
Trait Implementations§
Source§impl Debug for AtomicInstant
impl Debug for AtomicInstant
Source§impl Default for AtomicInstant
impl Default for AtomicInstant
Source§impl From<&AtomicInstant> for Instant
impl From<&AtomicInstant> for Instant
Source§fn from(value: &AtomicInstant) -> Self
fn from(value: &AtomicInstant) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl !Freeze for AtomicInstant
impl RefUnwindSafe for AtomicInstant
impl Send for AtomicInstant
impl Sync for AtomicInstant
impl Unpin for AtomicInstant
impl UnsafeUnpin for AtomicInstant
impl UnwindSafe for AtomicInstant
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