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<F: FnMut() -> Timespec> State<F>
impl<F: FnMut() -> Timespec> State<F>
Sourcepub fn new_with(now: F) -> State<F>
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");
Sourcepub fn get_time(&mut self) -> HLTimespec
pub fn get_time(&mut self) -> HLTimespec
Generates a timestamp from the clock.
Sourcepub fn update(&mut self, event: HLTimespec) -> HLTimespec
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> 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