logo

Struct uhlc::HLC

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

An Hybric Logical Clock generating Timestamps

Implementations

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);

Returns the HLC ID.

This ID is the specific identifier for this HLC instance.

Returns the HLC delta as NTP64.

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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.