pub struct Hlc { /* private fields */ }Expand description
Hybrid Logical Clock.
Thread-safe via interior Mutex. Create one per application lifetime,
pass by reference to write methods.
Implementations§
Source§impl Hlc
impl Hlc
pub fn try_new(device_id: String) -> Result<Hlc, PathTokenError>
Sourcepub fn seed(&self, high_water: &Timestamp)
pub fn seed(&self, high_water: &Timestamp)
Seed the clock’s monotonic state from a persisted high-water mark so it cannot mint a stamp behind a value it minted (or saw) before a restart.
Idempotent and monotonic: a seed below the current state is ignored, so
re-seeding can only push the clock forward. The seeded device_id is
irrelevant — only millis/counter gate future stamps.
Sourcepub fn high_water(&self) -> Timestamp
pub fn high_water(&self) -> Timestamp
Sourcepub fn wall_now_ms(&self) -> u64
pub fn wall_now_ms(&self) -> u64
The receiver’s current wall-clock millis, read from the same injected
source the clock stamps from. This is the reference the pull bounds an
incoming _updated_at against (see Timestamp::is_within_future_bound):
it is the receiver’s view of “now”, in the same millis unit as a stamp’s
physical component — never an author-supplied value. Read once per pull and
passed down, not sampled in a loop.
Sourcepub fn now(&self) -> Timestamp
pub fn now(&self) -> Timestamp
Generate a new timestamp. Guaranteed to be greater than any previous timestamp returned by this clock.
Sourcepub fn advance_past(&self, remote: &Timestamp)
pub fn advance_past(&self, remote: &Timestamp)
Record an applied row’s _updated_at as the clock floor, so the next local
stamp sorts causally after it. remote is an authoritative register
value the LWW layer already accepted and wrote to disk — never an
untrusted peer wall clock — so recording it is unconditional: no skew
cap. Capping here would let the next local edit mint a stamp below an
already-stored applied row and lose LWW to it.
Monotonic: a remote ahead of the current state becomes the state floor;
one behind it is ignored. Either way the next [now] outranks remote.
Auto Trait Implementations§
impl !Freeze for Hlc
impl !RefUnwindSafe for Hlc
impl Send for Hlc
impl Sync for Hlc
impl Unpin for Hlc
impl UnsafeUnpin for Hlc
impl !UnwindSafe for Hlc
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more