switchy_uuid
Switchable UUID generation supporting both production and simulation modes.
Overview
This package provides UUID v4 generation with configurable behavior:
- Production mode: Cryptographically secure random UUIDs via the standard
uuidcrate - Simulation mode: Deterministic, seeded UUIDs for reproducible testing
Features
- Switchable UUID generation based on feature flags
- Environment-controlled seeding for deterministic UUIDs
- Compatible with standard
uuid::Uuidtype - Zero-cost abstraction when using only one mode
Installation
[]
= "0.1.0"
Usage
use ;
// Generate UUID
let id = new_v4;
// Generate UUID as string
let token = new_v4_string;
Core Uuid API
new_v4() returns switchy_uuid::Uuid, which provides parsing and conversion helpers:
use Uuid;
let id = new_v4;
let parsed = parse_str.unwrap;
assert_eq!;
Simulation Mode
When the simulator feature is enabled (default), UUIDs are generated deterministically using a seeded random number generator. Control the seed via:
SIMULATOR_UUID_SEED=12345 # Default seed if not specified
Feature Flags
uuid(default): Enable standard UUID generation usinguuid::Uuid::new_v4()simulator(default): Enable deterministic UUID generation with seeded RNGserde: Enable serde serialization/deserialization support for theUuidtypefail-on-warnings: Treat compiler warnings as errors
Note: When both uuid and simulator are enabled, simulator takes precedence.