Struct uhlc::HLC

source ·
pub struct HLC { /* private fields */ }
Expand description

An Hybric Logical Clock generating Timestamps

Implementations§

source§

impl HLC

source

pub fn new_timestamp(&self) -> Timestamp

Generate a new Timestamp.

This timestamp is unique in the system and is always greater than the latest timestamp generated by the HLC and than the latest incoming timestamp that was used to update this HLC (using HLC::update_with_timestamp()).

§Examples
use uhlc::HLC;

let hlc = HLC::default();
let ts1 =  hlc.new_timestamp();
let ts2 =  hlc.new_timestamp();
assert!(ts2 > ts1);
source

pub fn get_id(&self) -> &ID

Returns the HLC ID.

This ID is the specific identifier for this HLC instance.

source

pub fn get_delta(&self) -> &NTP64

Returns the HLC delta as NTP64.

The maximum delta accepted by an HLC when updating it’s logical clock calling HLC::update_with_timestamp().

source

pub fn update_with_timestamp(&self, timestamp: &Timestamp) -> Result<(), String>

Update this HLC with a Timestamp.

Typically, this timestamp should have been generated by another HLC. If the timestamp exceeds the current time of this HLC by more than the configured maximum delta (see HLCBuilder::with_max_delta()) an Err is returned.

§Examples
use uhlc::HLC;

let hlc1 = HLC::default();

// update the HLC with a timestamp incoming from another HLC
// (typically remote, but not in this example...)
let hlc2 = HLC::default();
let other_ts = hlc2.new_timestamp();
if ! hlc1.update_with_timestamp(&other_ts).is_ok() {
    println!(r#"The incoming timestamp would make this HLC
             to drift too much. You should refuse it!"#);
}

let ts = hlc1.new_timestamp();
assert!(ts > other_ts);

Trait Implementations§

source§

impl Default for HLC

source§

fn default() -> Self

Create a new HLC with a random u128 ID and using system_time_clock() as physical clock. This is equivalent to HLCBuilder::default().build()

Auto Trait Implementations§

§

impl RefUnwindSafe for HLC

§

impl Send for HLC

§

impl Sync for HLC

§

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

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

§

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

§

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