Skip to main content

HlcGenerator

Struct HlcGenerator 

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

Issues monotonically increasing HLCs for one device, folding in the highest HLC observed from remote ops so causality survives clock skew.

Implementations§

Source§

impl HlcGenerator

Source

pub fn new(device_id: impl Into<String>) -> Self

A generator for device_id starting at wall time zero.

Source

pub fn next(&self, clock: &dyn Clock) -> Hlc

Issue the next HLC, strictly greater than every previous one issued or observed, using clock for the wall component.

Negative clock readings are clamped to 0 (the sortable encoding is only order-preserving for non-negative wall times — see Clock); if the logical counter is exhausted under a stalled clock, the wall component advances logically instead (HLC semantics permit the wall to run ahead of the physical clock).

Source

pub fn observe(&self, remote: &Hlc)

Fold in an HLC observed from a remote op so subsequently issued HLCs sort after it. Negative remote wall times are ignored (they are rejected at ingest by crate::Grit::apply_remote).

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.