Skip to main content

Hlc

Struct Hlc 

Source
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

Source

pub fn try_new(device_id: String) -> Result<Hlc, PathTokenError>

Source

pub fn new(device_id: String) -> Hlc

Create a new HLC with the given device ID.

Source

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.

Source

pub fn high_water(&self) -> Timestamp

The clock’s current high-water mark: a Timestamp at the latest millis/counter this clock has reached. Persist this whenever the clock advances (on stamp and on apply-merge) and feed it back to Hlc::seed on the next construction.

Source

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.

Source

pub fn now(&self) -> Timestamp

Generate a new timestamp. Guaranteed to be greater than any previous timestamp returned by this clock.

Source

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> 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,