pub struct HlcGenerator<S: ClockSource = UtcClock> { /* private fields */ }Expand description
Hybrid Logical Clock (HLC) generator.
Implementations§
Source§impl HlcGenerator<UtcClock>
impl HlcGenerator<UtcClock>
Sourcepub fn new(max_drift: usize) -> Self
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<S: ClockSource> HlcGenerator<S>
impl<S: ClockSource> HlcGenerator<S>
Sourcepub fn timestamp(&self) -> HlcTimestamp
pub fn timestamp(&self) -> HlcTimestamp
Current timestamp.
Use next_timestamp() to get the
timestamp for local or send events.
Sourcepub fn next_timestamp(&self) -> Option<HlcTimestamp>
pub fn next_timestamp(&self) -> Option<HlcTimestamp>
Timestamp for the local or send event.
Sourcepub fn update(&self, incoming_state: &HlcTimestamp) -> HlcResult<HlcTimestamp>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more