Struct uhlc::HLCBuilder

source ·
pub struct HLCBuilder { /* private fields */ }
Expand description

The builder of HLC.

Examples

use std::{convert::TryFrom, time::Duration};
use uhlc::{HLCBuilder, ID};

let default_hlc = HLCBuilder::new().build();
println!("{}", default_hlc.new_timestamp());

let custom_hlc = HLCBuilder::new()
   .with_id(ID::try_from([0x01, 0x02, 0x03]).unwrap())
   .with_max_delta(Duration::from_secs(1))
   .build();
println!("{}", custom_hlc.new_timestamp());

Implementations§

Constructs a new HLCBuilder for the creation of an HLC, with the following default configuration:

Configure a specific identifier for the HLC to be created.

NOTE: the identifier must be unique in the system.

Configure a specific physical clock for the HLC to be created.

The clock parameter must be a function returning a new physical time (as an NTP64 at each call. The time returned by this clock doesn’t need to be monotonic: when the HLC generates a new timestamp from this time, it first checks if this time is greater than the previously generated timestamp. If not, the new timestamp it the previous one +1.

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

Trait Implementations§

Returns the “default value” for a type. Read more

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.