Skip to main content

HlcClock

Struct HlcClock 

Source
pub struct HlcClock<C: PhysicalClock = SystemClock> { /* private fields */ }
Expand description

Hybrid Logical Clock state machine.

Two core operations:

  • now() - generate a timestamp for a local event
  • update() - merge a remote timestamp into local state

now() always returns a strictly increasing timestamp. update() advances the internal clock state without generating a new timestamp. Timestamps are only generated by local events; received timestamps only advance the clock.

Implementations§

Source§

impl HlcClock<SystemClock>

Source

pub fn new() -> Self

Source§

impl<C: PhysicalClock> HlcClock<C>

Source

pub fn with_clock(clock: C) -> Self

Source

pub fn set_max_drift_ns(&mut self, max_drift_ns: i64)

Source

pub fn set_last(&mut self, ts: HlcTimestamp)

Call on startup to restore monotonicity after a restart.

Source

pub fn now(&mut self) -> Result<HlcTimestamp, ClockError>

Generate a monotonically increasing timestamp for a local event.

Source

pub fn update(&mut self, remote: HlcTimestamp) -> Result<(), ClockError>

Merge a remote timestamp into local state (does not generate a new timestamp).

Source

pub fn last_timestamp(&self) -> HlcTimestamp

Source

pub fn physical_clock(&self) -> &C

Trait Implementations§

Source§

impl Default for HlcClock<SystemClock>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<C> Freeze for HlcClock<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for HlcClock<C>
where C: RefUnwindSafe,

§

impl<C> Send for HlcClock<C>

§

impl<C> Sync for HlcClock<C>
where C: Sync,

§

impl<C> Unpin for HlcClock<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for HlcClock<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for HlcClock<C>
where C: UnwindSafe,

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

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V