pub struct ContextV7 { /* private fields */ }Expand description
An unsynchronized, reseeding counter that produces 42-bit values for version 7 UUIDs.
This type is:
- Reseeding: The counter is reseeded on each time interval (1ms) with a random 41-bit value. The 42nd bit is left unset so the counter can safely increment over the millisecond.
- Adjusting: The timestamp is incremented when the counter wraps within a time interval (1ms). All subsequent timestamps in that same interval will also be incremented until it changes and the counter is reseeded.
- Non-thread-safe: The underlying counter uses unsynchronized cells, so needs to be wrapped in a mutex to share.
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() -> ContextV7
pub const fn new() -> ContextV7
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) -> ContextV7
pub fn with_adjust_by_millis(self, millis: u32) -> ContextV7
Specify an amount to shift timestamps by to obfuscate their actual generation time.
Sourcepub fn with_additional_precision(self) -> ContextV7
pub fn with_additional_precision(self) -> ContextV7
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,
) -> <ContextV7 as ClockSequence>::Output
fn generate_sequence( &self, seconds: u64, subsec_nanos: u32, ) -> <ContextV7 as ClockSequence>::Output
Source§fn generate_timestamp_sequence(
&self,
seconds: u64,
subsec_nanos: u32,
) -> (<ContextV7 as ClockSequence>::Output, u64, u32)
fn generate_timestamp_sequence( &self, seconds: u64, subsec_nanos: u32, ) -> (<ContextV7 as ClockSequence>::Output, u64, u32)
Source§fn usable_bits(&self) -> usize
fn usable_bits(&self) -> usize
ClockSequence::generate_sequence
or ClockSequence::generate_timestamp_sequence. Read moreimpl RefUnwindSafe for ContextV7
Auto Trait Implementations§
impl !Freeze for ContextV7
impl Send for ContextV7
impl !Sync for ContextV7
impl Unpin for ContextV7
impl UnsafeUnpin for ContextV7
impl UnwindSafe for ContextV7
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more