hlc

Struct State

Source
pub struct State<F> { /* private fields */ }
Expand description

State is a hybrid logical clock.

§Examples

use hlc::{HLTimespec, State};
let mut s = State::new();
println!("{}", s.get_time()); // attach to outgoing event
let ext_event_ts = HLTimespec::new(12345, 67, 89); // external event's timestamp
let ext_event_recv_ts = s.update(ext_event_ts);

If access to the clock isn’t serializable, a convenience method returns a State wrapped in a Mutex:

use hlc::State;
let mut mu = State::new_sendable();
{
    let mut s = mu.lock().unwrap();
    s.get_time();
}

Implementations§

Source§

impl State<()>

Source

pub fn new() -> State<fn() -> Timespec>

Source

pub fn new_sendable() -> Mutex<State<fn() -> Timespec>>

Source§

impl<F: FnMut() -> Timespec> State<F>

Source

pub fn new_with(now: F) -> State<F>

Creates a hybrid logical clock with the supplied wall time. This is useful for tests or settings in which an alternative clock is used.

§Examples
use hlc::{HLTimespec, State};
let mut times = vec![time::Timespec { sec: 42, nsec: 9919 }];
let mut s = State::new_with(move || times.pop().unwrap());
let mut ts = s.get_time();
assert_eq!(format!("{}", ts), "42.9919+0");
Source

pub fn get_time(&mut self) -> HLTimespec

Generates a timestamp from the clock.

Source

pub fn update(&mut self, event: HLTimespec) -> HLTimespec

Assigns a timestamp to an event which happened at the given timestamp on a remote system.

Auto Trait Implementations§

§

impl<F> Freeze for State<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for State<F>
where F: RefUnwindSafe,

§

impl<F> Send for State<F>
where F: Send,

§

impl<F> Sync for State<F>
where F: Sync,

§

impl<F> Unpin for State<F>
where F: Unpin,

§

impl<F> UnwindSafe for State<F>
where F: UnwindSafe,

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>,

Source§

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>,

Source§

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.