pub struct HlcTimestamp(/* private fields */);Expand description
Hybrid logical clock (HLC) timestamp.
This is a wrapper around raw u64 data of HLC atomic timestamp.
The timestamp is represented as a 64-bit unsigned integer. The upper 42 bits represent the physical time in milliseconds since a custom epoch, and the lower 22 bits represent the logical clock count.
Normally, you don’t need to worry about the details of the representation.
Whenever you need to create a new timestamp, use the
new() to create a timestamp with the given time,
or from_parts() to create a timestamp with a
specific Unix timestamp (in ms) and logical clock count.
To get the physical time and logical clock count, use the
parts() which returns a tuple of (pt, lc).
Alternatively, rely on timestamp() and
count() methods to get the physical time and logical
clock count.
Finally, you can use the as_u64() method to get the raw
data, which is guaranteed to be monotonically increasing and capturing the
happens-before relationship.
Implementations§
Source§impl HlcTimestamp
impl HlcTimestamp
Sourcepub fn new(unix_timestamp: i64) -> HlcResult<Self>
pub fn new(unix_timestamp: i64) -> HlcResult<Self>
Creates a new HLC timestamp from incoming physical time.
Sourcepub fn from_parts(pt: i64, lc: u64) -> HlcResult<Self>
pub fn from_parts(pt: i64, lc: u64) -> HlcResult<Self>
Creates a new HLC timestamp from the given physical time and logical clock count.
Trait Implementations§
Source§impl Add<u64> for HlcTimestamp
impl Add<u64> for HlcTimestamp
Source§impl AddAssign<u64> for HlcTimestamp
impl AddAssign<u64> for HlcTimestamp
Source§fn add_assign(&mut self, ts: u64)
fn add_assign(&mut self, ts: u64)
+= operation. Read moreSource§impl Clone for HlcTimestamp
impl Clone for HlcTimestamp
Source§fn clone(&self) -> HlcTimestamp
fn clone(&self) -> HlcTimestamp
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HlcTimestamp
impl Debug for HlcTimestamp
Source§impl Default for HlcTimestamp
impl Default for HlcTimestamp
Source§fn default() -> HlcTimestamp
fn default() -> HlcTimestamp
Source§impl Display for HlcTimestamp
impl Display for HlcTimestamp
Source§impl Hash for HlcTimestamp
impl Hash for HlcTimestamp
Source§impl Ord for HlcTimestamp
impl Ord for HlcTimestamp
Source§fn cmp(&self, other: &HlcTimestamp) -> Ordering
fn cmp(&self, other: &HlcTimestamp) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for HlcTimestamp
impl PartialEq for HlcTimestamp
Source§impl PartialOrd for HlcTimestamp
impl PartialOrd for HlcTimestamp
Source§impl Sub<&HlcTimestamp> for &HlcTimestamp
impl Sub<&HlcTimestamp> for &HlcTimestamp
Source§impl Sub<&HlcTimestamp> for HlcTimestamp
impl Sub<&HlcTimestamp> for HlcTimestamp
Source§impl Sub<HlcTimestamp> for &HlcTimestamp
impl Sub<HlcTimestamp> for &HlcTimestamp
Source§impl Sub<u64> for HlcTimestamp
impl Sub<u64> for HlcTimestamp
Source§impl Sub for HlcTimestamp
impl Sub for HlcTimestamp
Source§impl SubAssign<u64> for HlcTimestamp
impl SubAssign<u64> for HlcTimestamp
Source§fn sub_assign(&mut self, ts: u64)
fn sub_assign(&mut self, ts: u64)
-= operation. Read more