Struct HlcGenerator

Source
pub struct HlcGenerator<T: CurrentTimestamp = UtcTimestamp> { /* private fields */ }
Expand description

Hybrid Logical Clock (HLC) generator.

Implementations§

Source§

impl<T: CurrentTimestamp> HlcGenerator<T>

Source

pub fn new() -> Self

Creates a new HLC clock without any drift.

Whenever the clock running on a single node is required, there is no need to worry about drift, as no adjustments are made to the clock, i.e. update() is never called.

Source

pub fn with_max_drift(max_drift: usize) -> Self

Creates a new HLC clock with the specified maximum drift.

Source

pub fn set_max_drift(&self, max_drift: usize)

Update the maximum drift.

Source

pub fn ts_provider(&self) -> Arc<T>

Get timestamp provider.

Useful for testing purposes, where manual timestamps are used.

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

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> Freeze for HlcGenerator<T>

§

impl<T = UtcTimestamp> !RefUnwindSafe for HlcGenerator<T>

§

impl<T> Send for HlcGenerator<T>
where T: Sync + Send,

§

impl<T> Sync for HlcGenerator<T>
where T: Sync + Send,

§

impl<T> Unpin for HlcGenerator<T>

§

impl<T = UtcTimestamp> !UnwindSafe for HlcGenerator<T>

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.