pub struct HybridLogicalClock<C> { /* private fields */ }Expand description
Stateful hybrid logical clock backed by a caller-supplied physical clock.
Implementations§
Source§impl<C> HybridLogicalClock<C>
impl<C> HybridLogicalClock<C>
Sourcepub fn open(
device_id: impl Into<String>,
physical_clock: C,
persisted: Option<HybridLogicalClockState>,
) -> Result<Self, HlcError>
pub fn open( device_id: impl Into<String>, physical_clock: C, persisted: Option<HybridLogicalClockState>, ) -> Result<Self, HlcError>
Opens a clock from optional persisted state.
State with invalid components, an unencodable value, or a different
device_id is treated as corrupt and replaced with zero state. The
caller owns loading and saving the snapshot.
§Errors
Returns HlcError::EmptyDeviceId when device_id is blank.
Sourcepub fn now(&mut self) -> Result<i64, HlcError>
pub fn now(&mut self) -> Result<i64, HlcError>
Returns the next local timestamp and advances the clock.
§Errors
Returns HlcError::InvalidPhysicalClock for an invalid clock reading.
Returns HlcError::ExceedsSafeInteger when no later safe timestamp is
available. State remains unchanged on error.
Sourcepub fn observe(&mut self, remote_timestamp: i64) -> Result<i64, HlcError>
pub fn observe(&mut self, remote_timestamp: i64) -> Result<i64, HlcError>
Observes a remote timestamp and returns a timestamp ordered after it.
§Errors
Returns HlcError::InvalidTimestamp for invalid remote input,
HlcError::InvalidPhysicalClock for an invalid local clock reading,
or HlcError::ExceedsSafeInteger when no later timestamp is available.
State remains unchanged on error.
Sourcepub fn snapshot(&self) -> HybridLogicalClockState
pub fn snapshot(&self) -> HybridLogicalClockState
Returns an owned snapshot suitable for caller-controlled persistence.