Skip to main content

HybridLogicalClock

Struct HybridLogicalClock 

Source
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>
where C: FnMut() -> i64,

Source

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.

Source

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.

Source

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.

Source

pub fn snapshot(&self) -> HybridLogicalClockState

Returns an owned snapshot suitable for caller-controlled persistence.

Auto Trait Implementations§

§

impl<C> Freeze for HybridLogicalClock<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for HybridLogicalClock<C>
where C: RefUnwindSafe,

§

impl<C> Send for HybridLogicalClock<C>
where C: Send,

§

impl<C> Sync for HybridLogicalClock<C>
where C: Sync,

§

impl<C> Unpin for HybridLogicalClock<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for HybridLogicalClock<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for HybridLogicalClock<C>
where C: UnwindSafe,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.