[][src]Crate uhlc

A Unique Hybrid Logical Clock.

This library is an implementation of an Hybrid Logical Clock (HLC) associated to a unique identifier. Thus, it is able to generate timestamps that are unique across a distributed system, without the need of a centralized time source.

Quick Start

use uhlc::HLC;

// create an HLC with a generated UUID and relying on SystemTime::now()
let hlc = HLC::default();

// generate timestamps
let ts1 = hlc.new_timestamp().await;
let ts2 = hlc.new_timestamp().await;
assert!(ts2 > ts1);

// 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().await;

if ! hlc.update_with_timestamp(&other_ts).await.is_ok() {
    println!(r#"The incoming timestamp would make this HLC
             to drift too much. You should refuse it!"#);
}

let ts3 = hlc.new_timestamp().await;
assert!(ts3 > ts2);
assert!(ts3 > other_ts);

Structs

HLC

An Hybric Logical Clock generating Timestamps

ID

An identifier for an HLC (MAX_SIZE bytes maximum). This struct has a constant memory size (holding internally a [u8; MAX_SIZE] + a usize), allowing allocations on the stack for better performances.

NTP64

A NTP 64-bits format as specified in RFC-5909

ParseIDError
ParseNTP64Error
ParseTimestampError
Timestamp

A timestamp made of a NTP64 and a crate::HLC's unique identifier.

Constants

CSIZE

The size of counter part in NTP64 (in bits)

DELTA_MS

HLC Delta in milliseconds: maximum accepted drift for an external timestamp.

Functions

system_time_clock

A physical clock relying on std::time::SystemTime::now().