Struct uhlc::HLC [−][src]
pub struct HLC { /* fields omitted */ }An Hybric Logical Clock generating Timestamps
Implementations
impl HLC[src]
impl HLC[src]pub fn with_system_time(id: ID) -> HLC[src]
pub fn with_system_time(id: ID) -> HLC[src]Create a new HLC with an id (must be unique) and using
system_time_clock() as physical clock.
Examples
use uhlc::HLC; let hlc = HLC::with_system_time(uuid::Uuid::new_v4().into()); println!("{}", hlc.new_timestamp());
pub fn new_timestamp(&self) -> Timestamp[src]
pub fn new_timestamp(&self) -> Timestamp[src]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);
pub fn update_with_timestamp(&self, timestamp: &Timestamp) -> Result<(), String>[src]
pub fn update_with_timestamp(&self, timestamp: &Timestamp) -> Result<(), String>[src]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 DELTA_MS
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);