Struct ShardableUuid
pub struct ShardableUuid(/* private fields */);Expand description
VPR’s canonical UUID representation (32 lowercase hex characters, no hyphens).
This wrapper type guarantees that once constructed, the contained UUID is in VPR’s canonical format. It provides type safety for UUID operations and ensures consistent path derivation across the system.
§Why no hyphens?
The hyphen-free format is specifically chosen to support the sharding scheme for
patient directories. The sharded_dir method uses simple
string slicing to extract shard prefixes:
550e8400e29b41d4a716446655440000
^^^^
||└─ shard level 2: chars[2..4] = "0e"
└──── shard level 1: chars[0..2] = "55"This creates paths like /patient_data/clinical/55/0e/550e8400e29b41d4a716446655440000.
If hyphens were present, we’d need to strip them before sharding or handle them in the slicing logic, adding unnecessary complexity. The hyphen-free format gives us a clean, predictable character stream that’s trivial to slice and use directly as filesystem paths.
Note: Other identifiers that don’t use sharding (such as letter IDs) may use RFC 4122 format with hyphens for better readability.
§When to use this type
Use this wrapper whenever you are:
- Accepting a UUID string from outside the core (CLI input, API request, etc), or
- Deriving a sharded storage path for a patient.
- Generating new patient identifiers.
Once you have a ShardableUuid, you can safely assume the internal UUID is valid
and in canonical form.
§Construction
ShardableUuid::newgenerates a new canonical UUID (for new patient records).ShardableUuid::parsevalidates an externally supplied identifier.
§Errors
ShardableUuid::parse returns [UuidError::InvalidInput] if the input is not already
canonical.
§Display format
When displayed or converted to string, ShardableUuid always produces the canonical
32-character lowercase hex format without hyphens.
Implementations§
§impl ShardableUuid
impl ShardableUuid
pub fn new() -> ShardableUuid
pub fn new() -> ShardableUuid
Generates a new UUID in VPR’s canonical form.
This is suitable for allocating a fresh identifier during patient creation. The generated UUID is cryptographically secure and follows RFC 4122 version 4.
§Returns
Returns a newly generated canonical UUID wrapped in ShardableUuid.
pub fn parse(input: &str) -> Result<ShardableUuid, UuidError>
pub fn parse(input: &str) -> Result<ShardableUuid, UuidError>
Validates and parses a UUID string that must already be in VPR’s canonical form.
This does not normalise other common UUID forms (for example, hyphenated or uppercase). Callers must provide the canonical representation. This strict validation ensures consistency and prevents issues with different UUID representations.
§Arguments
input- UUID string to validate and wrap. Must be exactly 32 lowercase hex characters.
§Returns
Returns a validated ShardableUuid on success.
§Errors
Returns [UuidError::InvalidInput] if input is not in canonical form.
pub fn from_uuid(uuid: Uuid) -> ShardableUuid
pub fn from_uuid(uuid: Uuid) -> ShardableUuid
Creates a ShardableUuid from an existing uuid::Uuid.
This constructor wraps a Uuid that is already known to be valid,
avoiding the overhead of string parsing and validation. Use this when
converting internal Uuid values that are already validated.
§Arguments
uuid- A valid UUID to wrap.
§Returns
Returns a ShardableUuid wrapping the provided UUID.
pub fn is_canonical(input: &str) -> bool
pub fn is_canonical(input: &str) -> bool
Returns true if input is in VPR’s canonical UUID form.
This is a purely syntactic check that validates:
- Exactly 32 bytes long
- Contains only lowercase hex characters (
0-9anda-f)
This method is fast and can be used for pre-validation before calling ShardableUuid::parse.
§Arguments
input- Candidate UUID string to validate.
§Returns
Returns true if input is canonical, otherwise false.
pub fn sharded_dir(&self, parent_dir: &Path) -> PathBuf
pub fn sharded_dir(&self, parent_dir: &Path) -> PathBuf
Returns parent_dir/<s1>/<s2>/<uuid>/ where s1/s2 are derived from this UUID.
This implements VPR’s sharding scheme:
s1is the first two hex characters of the UUIDs2is the next two hex characters- The full UUID forms the leaf directory
This sharding prevents filesystem performance issues with large numbers of patient directories in a single location.
§Arguments
parent_dir- Base directory under which to shard the UUID.
§Returns
Returns the fully qualified sharded directory path for this UUID.
Trait Implementations§
§impl Clone for ShardableUuid
impl Clone for ShardableUuid
§fn clone(&self) -> ShardableUuid
fn clone(&self) -> ShardableUuid
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for ShardableUuid
impl Debug for ShardableUuid
§impl Default for ShardableUuid
impl Default for ShardableUuid
§fn default() -> ShardableUuid
fn default() -> ShardableUuid
§impl Display for ShardableUuid
impl Display for ShardableUuid
§impl FromStr for ShardableUuid
impl FromStr for ShardableUuid
§fn from_str(s: &str) -> Result<ShardableUuid, <ShardableUuid as FromStr>::Err>
fn from_str(s: &str) -> Result<ShardableUuid, <ShardableUuid as FromStr>::Err>
Parses a string into a ShardableUuid, requiring canonical form.
This is equivalent to calling ShardableUuid::parse.
§Errors
Returns [UuidError::InvalidInput] if the string is not in canonical UUID form.
§impl Hash for ShardableUuid
impl Hash for ShardableUuid
§impl PartialEq for ShardableUuid
impl PartialEq for ShardableUuid
impl Eq for ShardableUuid
impl StructuralPartialEq for ShardableUuid
Auto Trait Implementations§
impl Freeze for ShardableUuid
impl RefUnwindSafe for ShardableUuid
impl Send for ShardableUuid
impl Sync for ShardableUuid
impl Unpin for ShardableUuid
impl UnwindSafe for ShardableUuid
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request