pub struct Timestamp { /* private fields */ }
Expand description
A timestamp that can be encoded into a UUID.
This type abstracts the specific encoding, so versions 1, 6, and 7 UUIDs can both be supported through the same type, even though they have a different representation of a timestamp.
§References
Implementations§
source§impl Timestamp
impl Timestamp
sourcepub fn now(context: impl ClockSequence<Output = impl Into<u128>>) -> Self
pub fn now(context: impl ClockSequence<Output = impl Into<u128>>) -> Self
Get a timestamp representing the current system time and up to a 128-bit counter.
This method defers to the standard library’s SystemTime
type.
§Panics
This method will panic if calculating the elapsed time since the Unix epoch fails.
sourcepub const fn from_rfc4122(ticks: u64, counter: u16) -> Self
pub const fn from_rfc4122(ticks: u64, counter: u16) -> Self
Construct a Timestamp
from an RFC 9562 timestamp and 14-bit counter, as used
in versions 1 and 6 UUIDs.
§Overflow
If conversion from RFC 9562 ticks to the internal timestamp format would overflow it will wrap.
sourcepub const fn from_unix_time(
seconds: u64,
subsec_nanos: u32,
counter: u128,
usable_counter_bits: u8
) -> Self
pub const fn from_unix_time( seconds: u64, subsec_nanos: u32, counter: u128, usable_counter_bits: u8 ) -> Self
Construct a Timestamp
from a Unix timestamp and up to a 128-bit counter, as used in version 7 UUIDs.
sourcepub fn from_unix(
context: impl ClockSequence<Output = impl Into<u128>>,
seconds: u64,
subsec_nanos: u32
) -> Self
pub fn from_unix( context: impl ClockSequence<Output = impl Into<u128>>, seconds: u64, subsec_nanos: u32 ) -> Self
Construct a Timestamp
from a Unix timestamp and up to a 128-bit counter, as used in version 7 UUIDs.
sourcepub const fn to_rfc4122(&self) -> (u64, u16)
pub const fn to_rfc4122(&self) -> (u64, u16)
Get the value of the timestamp as an RFC 9562 timestamp and counter, as used in versions 1 and 6 UUIDs.
§Overflow
If conversion from RFC 9562 ticks to the internal timestamp format would overflow it will wrap.
sourcepub const fn to_unix(&self) -> (u64, u32)
pub const fn to_unix(&self) -> (u64, u32)
Get the value of the timestamp as a Unix timestamp, as used in version 7 UUIDs.
sourcepub const fn to_unix_nanos(&self) -> u32
👎Deprecated: use to_unix
instead; this method will be removed in a future release
pub const fn to_unix_nanos(&self) -> u32
to_unix
instead; this method will be removed in a future releaseGet the number of fractional nanoseconds in the Unix timestamp.
This method is deprecated and probably doesn’t do what you’re expecting it to. It doesn’t return the timestamp as nanoseconds since the Unix epoch, it returns the fractional seconds of the timestamp.