Skip to main content

HybridClock

Struct HybridClock 

Source
pub struct HybridClock { /* private fields */ }
Expand description

A Hybrid Logical Clock instance for a single node.

Call now to generate timestamps for local events. Call receive when processing a remote timestamp.

Accepts a NodeId (u64) on construction. Only the lower 16 bits are embedded in generated timestamps for compact tiebreaking.

Implementations§

Source§

impl HybridClock

Source

pub fn new(node_id: NodeId) -> Self

Create a new clock for the given node.

Accepts a NodeId (u64). Only the lower 16 bits are embedded in generated timestamps for compact tiebreaking.

On std targets, uses SystemTime for physical time. On no_std targets, use with_time_source.

Source

pub fn with_time_source(node_id: NodeId, time_fn: fn() -> u64) -> Self

Create a clock with a custom physical time source.

Accepts a NodeId (u64). Only the lower 16 bits are embedded in generated timestamps. The function should return milliseconds (monotonic if possible).

Source

pub fn now(&mut self) -> HybridTimestamp

Generate a timestamp for a local event.

Guarantees monotonically increasing timestamps even if the physical clock goes backward.

Source

pub fn receive(&mut self, remote: &HybridTimestamp) -> HybridTimestamp

Update the clock upon receiving a remote timestamp.

Returns a new timestamp that is strictly greater than both the local clock and the received timestamp.

Source

pub fn node_id(&self) -> u16

Get the node ID of this clock.

Source

pub fn last_timestamp(&self) -> HybridTimestamp

Get the last generated timestamp.

Trait Implementations§

Source§

impl Clone for HybridClock

Source§

fn clone(&self) -> HybridClock

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HybridClock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.