[−][src]Struct uhlc::HLC
An Hybric Logical Clock generating Timestamp
s
Implementations
impl HLC
[src]
pub fn with_clock(id: ID, clock: fn() -> NTP64) -> HLC
[src]
Create a new HLC
with an id
(must be unique) and a clock
(a function returning the current physical time as an NTP64
).
Examples
use uhlc::HLC; let hlc = HLC::with_clock( uuid::Uuid::new_v4().into(), uhlc::system_time_clock); println!("{}", hlc.new_timestamp().await);
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().await);
pub async 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().await; let ts2 = hlc.new_timestamp().await; assert!(ts2 > ts1);
pub async fn update_with_timestamp<'_, '_>(
&'_ self,
timestamp: &'_ Timestamp
) -> Result<(), String>
[src]
&'_ 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 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().await; if ! hlc1.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 ts = hlc1.new_timestamp().await; assert!(ts > other_ts);
Trait Implementations
impl Default for HLC
[src]
fn default() -> Self
[src]
Create a new HLC
with a generated UUID and using
system_time_clock()
as physical clock.
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,