pub struct UuidGenerator { /* private fields */ }Expand description
§UuidGenerator
A utility for generating sequential UUIDs within a namespace.
This struct provides a thread-safe way to generate UUIDs using the UUID v5 algorithm, which creates name-based UUIDs. Each generated UUID is unique within the given namespace and derived from an incrementing counter.
§Example
use uuid::Uuid;
use pricelevel::UuidGenerator;
let namespace = Uuid::new_v4(); // Create a random namespace
let generator = UuidGenerator::new(namespace);
let id1 = generator.next(); // Generate first UUID
let id2 = generator.next(); // Generate second UUIDThis is useful for applications that need deterministic but unique identifiers within a specific namespace context.
Implementations§
Source§impl UuidGenerator
A generator for creating sequential UUIDs based on a namespace.
impl UuidGenerator
A generator for creating sequential UUIDs based on a namespace.
This struct provides functionality to generate deterministic UUIDs in sequence by combining a namespace UUID with an incrementing counter value. Each generated UUID is created using the UUID v5 algorithm (SHA-1 hash-based).
§Examples
use uuid::Uuid;
use pricelevel::UuidGenerator;
let namespace = Uuid::parse_str("6ba7b810-9dad-11d1-80b4-00c04fd430c8").unwrap();
let generator = UuidGenerator::new(namespace);
let id1 = generator.next(); // First UUID
let id2 = generator.next(); // Second UUID (different from first)Sourcepub fn next(&self) -> Uuid
pub fn next(&self) -> Uuid
Generates the next UUID in sequence.
This method atomically increments an internal counter and uses its string representation as the name to generate a UUID v5 combined with the namespace.
§Returns
A new UUID that is deterministically derived from the namespace and the current counter value.