HlcGenerator

Struct HlcGenerator 

Source
pub struct HlcGenerator<S: ClockSource = UtcClock> { /* private fields */ }
Expand description

Hybrid Logical Clock (HLC) generator.

Implementations§

Source§

impl HlcGenerator<UtcClock>

Source

pub fn new(max_drift: usize) -> Self

Creates a new HLC clock with the specified maximum drift.

Set max_drift to 0, if the clock is running in a single node settings (useful for generating timestamp-based monotonically increasing IDs). In such settings, there is no need to worry about drift, as no adjustments are made to the clock, i.e. update() is never called.

Source§

impl HlcGenerator<ManualClock>

Source

pub fn manual(max_drift: usize) -> Self

Creates a new manual HLC clock with the specified maximum drift.

Useful for testing purposes, where manual timestamps are used.

Source

pub fn set_current_timestamp(&self, timestamp: i64)

Source§

impl<S: ClockSource> HlcGenerator<S>

Source

pub fn timestamp(&self) -> HlcTimestamp

Current timestamp.

Use next_timestamp() to get the timestamp for local or send events.

Source

pub fn next_timestamp(&self) -> Option<HlcTimestamp>

Timestamp for the local or send event.

Source

pub fn update(&self, incoming_state: &HlcTimestamp) -> HlcResult<HlcTimestamp>

Adjust the clock based on incoming timestamp.

Usually this happens when a timestamp is received from another node. An error may occur if drift is exceeded (if max_drift is set to 0, then such a check is ignored).

Updated timestamp is returned.

Trait Implementations§

Source§

impl Default for HlcGenerator<UtcClock>

Source§

fn default() -> Self

Creates a new HLC clock without any drift.

Auto Trait Implementations§

§

impl<S = UtcClock> !Freeze for HlcGenerator<S>

§

impl<S> RefUnwindSafe for HlcGenerator<S>
where S: RefUnwindSafe,

§

impl<S> Send for HlcGenerator<S>
where S: Send,

§

impl<S> Sync for HlcGenerator<S>
where S: Sync,

§

impl<S> Unpin for HlcGenerator<S>
where S: Unpin,

§

impl<S> UnwindSafe for HlcGenerator<S>
where S: 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, 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.