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

source

pub fn new() -> HLCBuilder

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

source

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.

source

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.

source

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().

source

pub fn build(self) -> HLC

Trait Implementations§

source§

impl Default for HLCBuilder

source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V