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§
source§impl HLCBuilder
impl HLCBuilder
sourcepub fn new() -> HLCBuilder
pub fn new() -> HLCBuilder
Constructs a new HLCBuilder for the creation of an HLC
, with the following default configuration:
- a random u128 as HLC identifier.
Can be changed calling
Self::with_id()
. system_time_clock()
as physical clock (i.e. the ). Can be changed callingSelf::with_clock()
.- 500 millisecond as maximum delta (i.e. the maximum accepted drift for an external timestamp).
Can be changed calling
Self::with_max_delta()
.
sourcepub fn with_id(self, id: ID) -> HLCBuilder
pub fn with_id(self, id: ID) -> HLCBuilder
Configure a specific identifier for the HLC to be created.
NOTE: the identifier must be unique in the system.
sourcepub fn with_clock(self, clock: fn() -> NTP64) -> HLCBuilder
pub fn with_clock(self, clock: fn() -> NTP64) -> HLCBuilder
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.
sourcepub fn with_max_delta(self, delta: Duration) -> HLCBuilder
pub fn with_max_delta(self, delta: Duration) -> HLCBuilder
Configure the maximum delta accepted by an HLC when updating it’s logical clock calling HLC::update_with_timestamp()
.
pub fn build(self) -> HLC
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for HLCBuilder
impl RefUnwindSafe for HLCBuilder
impl Send for HLCBuilder
impl Sync for HLCBuilder
impl Unpin for HLCBuilder
impl UnwindSafe for HLCBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more