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

§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

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>

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

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 uuid(&self) -> Uuid

Returns the UUID as a uuid::Uuid.

This method provides access to the underlying uuid::Uuid for operations that require the standard UUID library interface.

§Returns

Returns a copy of the inner UUID.

§Note

The returned UUID is guaranteed to be valid since ShardableUuid only contains validated UUIDs.

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-9 and a-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

Returns parent_dir/<s1>/<s2>/<uuid>/ where s1/s2 are derived from this UUID.

This implements VPR’s sharding scheme:

  • s1 is the first two hex characters of the UUID
  • s2 is 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

§

fn clone(&self) -> ShardableUuid

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for ShardableUuid

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for ShardableUuid

§

fn default() -> ShardableUuid

Returns the “default value” for a type. Read more
§

impl Display for ShardableUuid

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the UUID in canonical form (32 lowercase hex characters, no hyphens).

This ensures consistent string representation across the application.

§

impl FromStr for ShardableUuid

§

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.

§

type Err = UuidError

The associated error which can be returned from parsing.
§

impl Hash for ShardableUuid

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for ShardableUuid

§

fn eq(&self, other: &ShardableUuid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Eq for ShardableUuid

§

impl StructuralPartialEq for ShardableUuid

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more