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.
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.