Struct Context

Source
pub struct Context { /* private fields */ }
Expand description

A thread-safe, wrapping counter that produces 14-bit values.

This type works by:

  1. Atomically incrementing the counter value for each timestamp.
  2. 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

Source

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.

Source

pub fn new_random() -> Self

Construct a new context that’s initialized with a random value.

Trait Implementations§

Source§

impl ClockSequence for Context

Source§

type Output = u16

The type of sequence returned by this counter.
Source§

fn generate_sequence(&self, _seconds: u64, _nanos: u32) -> Self::Output

Get the next value in the sequence to feed into a timestamp. Read more
Source§

fn usable_bits(&self) -> usize

The number of usable bits from the least significant bit in the result of ClockSequence::generate_sequence or ClockSequence::generate_timestamp_sequence. Read more
Source§

fn generate_timestamp_sequence( &self, seconds: u64, subsec_nanos: u32, ) -> (Self::Output, u64, u32)

Get the next value in the sequence, potentially also adjusting the timestamp. Read more
Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,