pub struct ConsistentTimestamp(pub u64);Expand description
Timestamp that tries to be consistent and monotonic across cluster by incorporating node’s unique id and a per-node counter.
It’s designed to have the same resolution as a nanoseconds precision timestamp by encoding node id and counter in nanoseconds.
It is similar to Twitter’s Snowflake (https://t.co/cLj36EQWR1) even though it has not been designed out of it. As opposed to Snowflake, this consistent timestamp has a per node sequence number instead of per thread.
Tuple Fields§
§0: u64Implementations§
Source§impl ConsistentTimestamp
impl ConsistentTimestamp
pub fn from_context( unix_elapsed: Duration, counter: u64, node_clock_id: u16, ) -> ConsistentTimestamp
pub fn from_unix_elapsed(dur: Duration) -> ConsistentTimestamp
pub fn to_datetime(self) -> DateTime<Utc>
pub fn unix_elapsed_duration(self) -> Duration
Trait Implementations§
Source§impl Add<Duration> for ConsistentTimestamp
impl Add<Duration> for ConsistentTimestamp
Source§impl Add for ConsistentTimestamp
impl Add for ConsistentTimestamp
Source§type Output = ConsistentTimestamp
type Output = ConsistentTimestamp
The resulting type after applying the
+ operator.Source§impl Clone for ConsistentTimestamp
impl Clone for ConsistentTimestamp
Source§fn clone(&self) -> ConsistentTimestamp
fn clone(&self) -> ConsistentTimestamp
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 moreSource§impl Debug for ConsistentTimestamp
impl Debug for ConsistentTimestamp
Source§impl<'de> Deserialize<'de> for ConsistentTimestamp
impl<'de> Deserialize<'de> for ConsistentTimestamp
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Self, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Self, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<ConsistentTimestamp> for DateTime<Utc>
impl From<ConsistentTimestamp> for DateTime<Utc>
Source§fn from(s: ConsistentTimestamp) -> Self
fn from(s: ConsistentTimestamp) -> Self
Converts to this type from the input type.
Source§impl From<ConsistentTimestamp> for Timestamp
impl From<ConsistentTimestamp> for Timestamp
Source§fn from(ts: ConsistentTimestamp) -> Self
fn from(ts: ConsistentTimestamp) -> Self
Converts to this type from the input type.
Source§impl From<ConsistentTimestamp> for u64
impl From<ConsistentTimestamp> for u64
Source§fn from(ts: ConsistentTimestamp) -> Self
fn from(ts: ConsistentTimestamp) -> Self
Converts to this type from the input type.
Source§impl From<Timestamp> for ConsistentTimestamp
impl From<Timestamp> for ConsistentTimestamp
Source§impl From<u64> for ConsistentTimestamp
impl From<u64> for ConsistentTimestamp
Source§impl Hash for ConsistentTimestamp
impl Hash for ConsistentTimestamp
Source§impl Ord for ConsistentTimestamp
impl Ord for ConsistentTimestamp
Source§fn cmp(&self, other: &ConsistentTimestamp) -> Ordering
fn cmp(&self, other: &ConsistentTimestamp) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for ConsistentTimestamp
impl PartialEq for ConsistentTimestamp
Source§impl PartialOrd for ConsistentTimestamp
impl PartialOrd for ConsistentTimestamp
Source§impl Serialize for ConsistentTimestamp
impl Serialize for ConsistentTimestamp
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Source§impl Sub<Duration> for ConsistentTimestamp
impl Sub<Duration> for ConsistentTimestamp
Source§impl Sub for ConsistentTimestamp
impl Sub for ConsistentTimestamp
impl Copy for ConsistentTimestamp
impl Eq for ConsistentTimestamp
impl StructuralPartialEq for ConsistentTimestamp
Auto Trait Implementations§
impl Freeze for ConsistentTimestamp
impl RefUnwindSafe for ConsistentTimestamp
impl Send for ConsistentTimestamp
impl Sync for ConsistentTimestamp
impl Unpin for ConsistentTimestamp
impl UnwindSafe for ConsistentTimestamp
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more