pub struct HybridClock { /* private fields */ }Expand description
Implementations§
Source§impl HybridClock
impl HybridClock
Sourcepub fn new(node_id: NodeId) -> Self
pub fn new(node_id: NodeId) -> Self
Create a new clock for the given node.
Accepts a NodeId (u64). Only the lower 16 bits are embedded in
generated timestamps for compact tiebreaking.
On std targets, uses SystemTime for physical time.
On no_std targets, use with_time_source.
Sourcepub fn with_time_source(node_id: NodeId, time_fn: fn() -> u64) -> Self
pub fn with_time_source(node_id: NodeId, time_fn: fn() -> u64) -> Self
Create a clock with a custom physical time source.
Accepts a NodeId (u64). Only the lower 16 bits are embedded in
generated timestamps. The function should return milliseconds
(monotonic if possible).
Sourcepub fn now(&mut self) -> HybridTimestamp
pub fn now(&mut self) -> HybridTimestamp
Generate a timestamp for a local event.
Guarantees monotonically increasing timestamps even if the physical clock goes backward.
Sourcepub fn receive(&mut self, remote: &HybridTimestamp) -> HybridTimestamp
pub fn receive(&mut self, remote: &HybridTimestamp) -> HybridTimestamp
Update the clock upon receiving a remote timestamp.
Returns a new timestamp that is strictly greater than both the local clock and the received timestamp.
Sourcepub fn last_timestamp(&self) -> HybridTimestamp
pub fn last_timestamp(&self) -> HybridTimestamp
Get the last generated timestamp.
Trait Implementations§
Source§impl Clone for HybridClock
impl Clone for HybridClock
Source§fn clone(&self) -> HybridClock
fn clone(&self) -> HybridClock
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for HybridClock
impl RefUnwindSafe for HybridClock
impl Send for HybridClock
impl Sync for HybridClock
impl Unpin for HybridClock
impl UnsafeUnpin for HybridClock
impl UnwindSafe for HybridClock
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