[−][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 |
NTP64 | A NTP 64-bits format as specified in RFC-5909 |
Timestamp | A timestamp made of a |
Constants
CSIZE | The size of counter part in |
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(). |