pub struct ContextV7 { /* private fields */ }
Expand description
An unsynchronized, reseeding counter that produces 42-bit values.
This type works by:
- Reseeding the counter each millisecond with a random 41-bit value. The 42nd bit is left unset so the counter can safely increment over the millisecond.
- Wrapping the counter back to zero if it overflows its 42-bit storage and adding a millisecond to the timestamp.
The counter can use additional sub-millisecond precision from the timestamp to better synchronize UUID sorting in distributed systems. In these cases, the additional precision is masked into the left-most 12 bits of the counter. The counter is still reseeded on each new millisecond, and incremented within the millisecond. This behavior may change in the future. The only guarantee is monotonicity.
This type can be used when constructing version 7 UUIDs. When used to construct a version 7 UUID, the 42-bit counter will be padded with random data. This type can be used to maintain ordering of UUIDs within the same millisecond.
This type should not be used when constructing version 1 or version 6 UUIDs. When used to construct a version 1 or version 6 UUID, only the 14 least significant bits of the counter will be used.
Implementations§
Source§impl ContextV7
impl ContextV7
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct a new context that will reseed its counter on the first non-zero timestamp it receives.
Sourcepub fn with_adjust_by_millis(self, millis: u32) -> Self
pub fn with_adjust_by_millis(self, millis: u32) -> Self
Specify an amount to shift timestamps by to obfuscate their actual generation time.
Sourcepub fn with_additional_precision(self) -> Self
pub fn with_additional_precision(self) -> Self
Use the leftmost 12 bits of the counter for additional timestamp precision.
This method can provide better sorting for distributed applications that generate frequent UUIDs by trading a small amount of entropy for better counter synchronization. Note that the counter will still be reseeded on millisecond boundaries, even though some of its storage will be dedicated to the timestamp.
Trait Implementations§
Source§impl ClockSequence for ContextV7
impl ClockSequence for ContextV7
Source§fn generate_sequence(&self, seconds: u64, subsec_nanos: u32) -> Self::Output
fn generate_sequence(&self, seconds: u64, subsec_nanos: u32) -> Self::Output
Source§fn generate_timestamp_sequence(
&self,
seconds: u64,
subsec_nanos: u32,
) -> (Self::Output, u64, u32)
fn generate_timestamp_sequence( &self, seconds: u64, subsec_nanos: u32, ) -> (Self::Output, u64, u32)
Source§fn usable_bits(&self) -> usize
fn usable_bits(&self) -> usize
ClockSequence::generate_sequence
or ClockSequence::generate_timestamp_sequence
. Read more