Struct hlc::State [] [src]

pub struct State<F> { /* fields omitted */ }

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();
}

Methods

impl State<()>
[src]

impl<F: FnMut() -> Timespec> State<F>
[src]

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");

Generates a timestamp from the clock.

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