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.

Implementations§

Source§

impl HybridClock

Source

pub fn new(node_id: u16) -> Self

Create a new clock for the given node.

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

Source

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

Create a clock with a custom physical time source. 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.

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