pub struct Context { /* private fields */ }
Expand description
A thread-safe, wrapping counter that produces 14-bit values.
This type works by:
- Atomically incrementing the counter value for each timestamp.
- Wrapping the counter back to zero if it overflows its 14-bit storage.
This type should be used when constructing versions 1 and 6 UUIDs.
This type should not be used when constructing version 7 UUIDs. When used to construct a version 7 UUID, the 14-bit counter will be padded with random data. Counter overflows are more likely with a 14-bit counter than they are with a 42-bit counter when working at millisecond precision. This type doesn’t attempt to adjust the timestamp on overflow.
Implementations§
Source§impl Context
impl Context
Sourcepub const fn new(count: u16) -> Self
pub const fn new(count: u16) -> Self
Construct a new context that’s initialized with the given value.
The starting value should be a random number, so that UUIDs from
different systems with the same timestamps are less likely to collide.
When the rng
feature is enabled, prefer the Context::new_random
method.
Sourcepub fn new_random() -> Self
pub fn new_random() -> Self
Construct a new context that’s initialized with a random value.
Trait Implementations§
Source§impl ClockSequence for Context
impl ClockSequence for Context
Source§fn generate_sequence(&self, _seconds: u64, _nanos: u32) -> Self::Output
fn generate_sequence(&self, _seconds: u64, _nanos: u32) -> Self::Output
Source§fn usable_bits(&self) -> usize
fn usable_bits(&self) -> usize
ClockSequence::generate_sequence
or ClockSequence::generate_timestamp_sequence
. Read more