pub struct NTP64(pub u64);
Expand description
A NTP 64-bits format as specified in RFC-5909
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Seconds |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Fraction |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The 1st 32-bits part is the number of second since the EPOCH of the physical clock,
and the 2nd 32-bits part is the fraction of second.
In case it’s part of a crate::Timestamp
generated by an crate::HLC
the last few bits
of the Fraction part are replaced by the HLC logical counter.
The size of this counter currently hard-coded as crate::CSIZE
.
Note that this timestamp in actually similar to a std::time::Duration
, as it doesn’t
define an EPOCH. Only the NTP64::to_system_time()
and std::fmt::Display::fmt()
operations assume that
it’s relative to UNIX_EPOCH (1st Jan 1970) to display the timpestamp in RFC-3339 format.
Tuple Fields§
§0: u64
Implementations§
source§impl NTP64
impl NTP64
sourcepub fn as_secs_f64(&self) -> f64
pub fn as_secs_f64(&self) -> f64
Returns this NTP64 as a f64 in seconds.
The integer part of the f64 is the NTP64’s Seconds part.
The decimal part of the f64 is the result of a division of NTP64’s Fraction part divided by 2^32.
Considering the probable large number of Seconds (for a time relative to UNIX_EPOCH), the precision of the resulting f64 might be in the order of microseconds.
Therefore, it should not be used for comparison. Directly comparing NTP64 objects is preferable.
sourcepub fn subsec_nanos(&self) -> u32
pub fn subsec_nanos(&self) -> u32
Returns the 32-bits fraction of second part converted to nanoseconds.
sourcepub fn to_duration(self) -> Duration
pub fn to_duration(self) -> Duration
Convert to a Duration
.
sourcepub fn to_system_time(self) -> SystemTime
pub fn to_system_time(self) -> SystemTime
Convert to a SystemTime
(making the assumption that this NTP64 is relative to UNIX_EPOCH
).
Trait Implementations§
source§impl AddAssign<u64> for NTP64
impl AddAssign<u64> for NTP64
source§fn add_assign(&mut self, other: u64)
fn add_assign(&mut self, other: u64)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for NTP64
impl<'de> Deserialize<'de> for NTP64
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 Ord for NTP64
impl Ord for NTP64
source§impl PartialEq for NTP64
impl PartialEq for NTP64
source§impl PartialOrd for NTP64
impl PartialOrd for NTP64
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<u64> for NTP64
impl SubAssign<u64> for NTP64
source§fn sub_assign(&mut self, other: u64)
fn sub_assign(&mut self, other: u64)
-=
operation. Read more