pub struct Timestamp { /* private fields */ }Expand description
A timestamp made of a NTP64 and a crate::HLC’s unique identifier.
§Conversion to/from String
A Timestamp is formatted to a String as such:  "<ntp64_time>/<hlc_id_hexadecimal>"
2 different String representations are supported:
<ntp64_time>as an unsigned integer in decimal format
- Such conversion is lossless and thus bijective.
 - Timestamp to String: use 
std::fmt::Display::fmt()orstd::string::ToString::to_string(). - String to Timestamp: use 
std::str::FromStr::from_str() 
<ntp64_time>as a RFC3339 (human readable) format:
- Such conversion loses some precision because of rounding when conferting the fraction part to nanoseconds
 - As a consequence it’s not bijective: a Timestamp converted to RFC3339 String and then converted back to Timestamp might result to a different time.
 - Timestamp to String: use 
std::fmt::Display::fmt()with the alternate flag ({:#}) orTimestamp::to_string_rfc3339_lossy(). - String to Timestamp: use 
Timestamp::parse_rfc3339() 
Implementations§
Source§impl Timestamp
 
impl Timestamp
pub fn new(time: NTP64, id: ID) -> Timestamp
pub fn get_time(&self) -> &NTP64
pub fn get_id(&self) -> &ID
pub fn get_diff_duration(&self, other: &Timestamp) -> Duration
Sourcepub fn to_string_rfc3339_lossy(&self) -> String
 
pub fn to_string_rfc3339_lossy(&self) -> String
Convert to a RFC3339 time representation with nanoseconds precision. e.g.: `“2024-07-01T13:51:12.129693000Z/33”``
Sourcepub fn parse_rfc3339(s: &str) -> Result<Self, ParseTimestampError>
 
pub fn parse_rfc3339(s: &str) -> Result<Self, ParseTimestampError>
Parse a RFC3339 time representation into a NTP64.
Trait Implementations§
Source§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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Timestamp
 
impl Display for Timestamp
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
 
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats Timestamp as the time part followed by the ID part, with / as separator.
By default the time part is formatted as an unsigned integer in decimal format.
If the alternate flag {:#} is used, the time part is formatted with RFC3339 representation with nanoseconds precision.
§Examples
  use uhlc::*;
  use std::convert::TryFrom;
  let t =Timestamp::new(NTP64(7386690599959157260), ID::try_from([0x33]).unwrap());
  println!("{t}");    // displays: 7386690599959157260/33
  println!("{t:#}");  // displays: 2024-07-01T15:32:06.860479000Z/33Source§impl Ord for Timestamp
 
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
 
impl PartialOrd for Timestamp
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
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