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
impl DeterministicUuidFactory
Sourcepub fn new(seed: u64, generator_type: GeneratorType) -> Self
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 generationgenerator_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();Sourcepub fn with_sub_discriminator(
seed: u64,
generator_type: GeneratorType,
sub_discriminator: u8,
) -> Self
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.
Sourcepub fn with_counter(
seed: u64,
generator_type: GeneratorType,
start_counter: u64,
) -> Self
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 or for partitioned parallel generation where each thread gets a non-overlapping counter range.
Sourcepub fn for_partition(
seed: u64,
generator_type: GeneratorType,
partition_index: u8,
) -> Self
pub fn for_partition( seed: u64, generator_type: GeneratorType, partition_index: u8, ) -> Self
Create a factory for a specific partition in parallel generation.
Each partition gets a unique sub-discriminator so that counters starting from 0 in each partition still produce globally unique UUIDs. This avoids atomic contention between threads since each partition has its own factory.
Sourcepub fn next(&self) -> Uuid
pub fn next(&self) -> Uuid
Generate the next UUID in the sequence.
This method is thread-safe and can be called from multiple threads.
Sourcepub fn generate_at(&self, counter: u64) -> Uuid
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.
Sourcepub fn current_counter(&self) -> u64
pub fn current_counter(&self) -> u64
Get the current counter value.
Sourcepub fn set_counter(&self, value: u64)
pub fn set_counter(&self, value: u64)
Set the counter to a specific value.
Trait Implementations§
Source§impl Clone for DeterministicUuidFactory
impl Clone for DeterministicUuidFactory
Auto Trait Implementations§
impl !Freeze for DeterministicUuidFactory
impl RefUnwindSafe for DeterministicUuidFactory
impl Send for DeterministicUuidFactory
impl Sync for DeterministicUuidFactory
impl Unpin for DeterministicUuidFactory
impl UnsafeUnpin for DeterministicUuidFactory
impl UnwindSafe for DeterministicUuidFactory
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.