pub struct Timestamp(/* private fields */);
Expand description
Strictly monotonic timestamp since SystemTime::UNIX_EPOCH in microseconds.
The purpose of this timestamp is to unique per “user”, not globally,
it achieves this by:
1. Override the last byte with a random clock_id
, reducing the probability
of two matching timestamps across multiple machines/threads.
2. Guarantee that the remaining 3 bytes are ever increasing (strictly monotonic) within
the same thread regardless of the wall clock value
This timestamp is also serialized as BE bytes to remain sortable.
If a utf-8
encoding is necessary, it is encoded as base32::Alphabet::Crockford
to act as a sortable Id.
U64 (through pubky) of microseconds is valid for the next ~600 thousand years! i64 (in mainline) of microseconds is valid for the next ~300 thousand years!
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn now() -> Self
pub fn now() -> Self
Generate a Timestamp from the DEFAULT_FACTORY.
pub fn parse_http_date(date: &str) -> Result<Self, Error>
pub fn format_http_date(&self) -> String
Trait Implementations§
Source§impl AddAssign<u64> for Timestamp
impl AddAssign<u64> for Timestamp
Source§fn add_assign(&mut self, other: u64)
fn add_assign(&mut self, other: u64)
+=
operation. Read moreSource§impl AddAssign for Timestamp
impl AddAssign for Timestamp
Source§fn add_assign(&mut self, other: Timestamp)
fn add_assign(&mut self, other: Timestamp)
+=
operation. Read moreSource§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<SystemTime> for Timestamp
impl From<SystemTime> for Timestamp
Source§fn from(system_time: SystemTime) -> Self
fn from(system_time: SystemTime) -> Self
Source§impl From<Timestamp> for SystemTime
impl From<Timestamp> for SystemTime
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl SubAssign<u64> for Timestamp
impl SubAssign<u64> for Timestamp
Source§fn sub_assign(&mut self, other: u64)
fn sub_assign(&mut self, other: u64)
-=
operation. Read moreSource§impl SubAssign for Timestamp
impl SubAssign for Timestamp
Source§fn sub_assign(&mut self, other: Timestamp)
fn sub_assign(&mut self, other: Timestamp)
-=
operation. Read more