Skip to main content

DeterministicUuidFactory

Struct DeterministicUuidFactory 

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

A factory for generating deterministic UUIDs that are guaranteed unique across different generator types within the same seed.

§UUID Structure (16 bytes)

Bytes 0-5:   Seed (lower 48 bits)
Byte  6:     Generator type discriminator
Byte  7:     Version nibble (0x4_) | Sub-discriminator
Bytes 8-15:  Counter (64-bit, with variant bits set)

§Thread Safety

The counter uses AtomicU64 for thread-safe increments, allowing concurrent UUID generation from multiple threads.

Implementations§

Source§

impl DeterministicUuidFactory

Source

pub fn new(seed: u64, generator_type: GeneratorType) -> Self

Create a new UUID factory for a specific generator type.

§Arguments
  • seed - The global seed for deterministic generation
  • generator_type - The type of generator using this factory
§Example
use datasynth_core::uuid_factory::{DeterministicUuidFactory, GeneratorType};

let factory = DeterministicUuidFactory::new(12345, GeneratorType::JournalEntry);
let uuid = factory.next();
Source

pub fn with_sub_discriminator( seed: u64, generator_type: GeneratorType, sub_discriminator: u8, ) -> Self

Create a factory with a sub-discriminator for additional namespace separation.

Useful when the same generator type needs multiple independent UUID streams.

Source

pub fn with_counter( seed: u64, generator_type: GeneratorType, start_counter: u64, ) -> Self

Create a factory starting from a specific counter value.

Useful for resuming generation from a checkpoint.

Source

pub fn next(&self) -> Uuid

Generate the next UUID in the sequence.

This method is thread-safe and can be called from multiple threads.

Source

pub fn generate_at(&self, counter: u64) -> Uuid

Generate a UUID for a specific counter value without incrementing.

Useful for deterministic regeneration of specific UUIDs.

Source

pub fn current_counter(&self) -> u64

Get the current counter value.

Source

pub fn reset(&self)

Reset the counter to zero.

Source

pub fn set_counter(&self, value: u64)

Set the counter to a specific value.

Trait Implementations§

Source§

impl Clone for DeterministicUuidFactory

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeterministicUuidFactory

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V