Skip to main content

RealtimeClock

Struct RealtimeClock 

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

A monotonic realtime clock that ensures timestamps always move forward.

Wraps SystemTime but guarantees each now() call returns a timestamp strictly greater than all previous calls, even if the system clock jumps backwards. When the clock goes backwards, it increments from the last seen timestamp by one microsecond.

Implementations§

Source§

impl RealtimeClock

Source

pub fn new() -> Self

Create a new realtime clock initialized with the current system time.

Source

pub fn with_initial(initial: Microseconds) -> Self

Create a realtime clock initialized with a specific timestamp.

Useful for resuming from a persisted state (e.g., last journal entry).

Source

pub fn now(&self) -> Microseconds

Get the current monotonic timestamp in microseconds since Unix epoch.

Returns system time if it moved forward, otherwise returns last seen + 1µs.

Source

pub fn observe(&self, candidate: Microseconds) -> Microseconds

Observe an external timestamp and return a monotonic realtime value.

If the provided value is not strictly greater than the last seen timestamp, returns last_seen + 1us to preserve strict monotonicity.

Source

pub fn last_seen(&self) -> Microseconds

Get the last seen timestamp without advancing the clock.

Trait Implementations§

Source§

impl Debug for RealtimeClock

Source§

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

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

impl Default for RealtimeClock

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.