Struct TimestampId

pub struct TimestampId { /* private fields */ }
Expand description

A time-prefixed timestamp identifier for ordering events and records.

TimestampId combines a UTC timestamp with a UUID to create a globally unique, time-ordered identifier. This is the primary mechanism for ordering patient records in the VPR system.

§Format

YYYYMMDDTHHMMSS.mmmZ-<uuid>

Where:

  • YYYYMMDD - Date (year, month, day)
  • T - ISO 8601 separator
  • HHMMSS - Time (hours, minutes, seconds in 24-hour format)
  • .mmm - Milliseconds (3 digits)
  • Z - UTC timezone indicator
  • - - Separator between timestamp and UUID
  • <uuid> - Standard hyphenated UUID (8-4-4-4-12 format)

§Example

20260113T143522.045Z-550e8400-e29b-41d4-a716-446655440000
└─────────┬────────┘ └──────────────┬───────────────────┘
      timestamp                    UUID

§Design Properties

This is a value object with the following guarantees:

  • Immutable: Once created, the timestamp and UUID cannot be changed
  • Comparable: Implements PartialEq and Eq for equality checks
  • Hashable: Can be used as a key in hash maps and sets
  • Parseable: Can be constructed from a string representation
  • Clock-free: Does not access the system clock; use TimestampIdGenerator for generation
  • Thread-safe: Can be safely shared across threads (Send + Sync)

§Value Object Pattern

TimestampId follows the value object pattern from Domain-Driven Design:

  • It represents a conceptual whole (a point in time with unique identity)
  • It has no identity separate from its attributes
  • It is compared by value, not reference
  • It is immutable after construction

§Usage

§Monotonicity

When using TimestampIdGenerator, timestamps are guaranteed to be strictly increasing even if the system clock hasn’t advanced or moves backward. This is essential for:

  • Maintaining correct event ordering in distributed systems
  • Ensuring audit log integrity
  • Preventing timestamp collisions in high-frequency scenarios

§Thread Safety

TimestampId itself is thread-safe, but monotonicity guarantees require external synchronization (e.g., per-patient locks) when generating new IDs.

§Display and Parsing

The string representation uses hyphens in the UUID part for better readability. Format: 20260113T143522.045Z-550e8400-e29b-41d4-a716-446655440000

Parsing accepts the same format and validates both timestamp and UUID components.

§See Also

Implementations§

§

impl TimestampId

pub fn new(timestamp: DateTime<Utc>, uuid: Uuid) -> TimestampId

Constructs a TimestampId from explicit components.

This is a low-level constructor that assumes ordering and monotonicity have already been handled by the caller. For generating new IDs, prefer using TimestampIdGenerator::generate which provides monotonicity guarantees.

§Arguments
  • timestamp - The UTC timestamp for this identifier
  • uuid - The unique identifier component
§Returns

A new TimestampId with the specified components.

pub fn timestamp(&self) -> DateTime<Utc>

Returns the timestamp component.

This is the logical time associated with this identifier. In cases where monotonicity adjustments were applied, this may be slightly ahead of the actual system clock time.

§Returns

The UTC timestamp as a DateTime<Utc>.

pub fn uuid(&self) -> &Uuid

Returns a reference to the UUID component.

The UUID provides global uniqueness even when multiple events share the same timestamp.

§Returns

A reference to the Uuid component.

Trait Implementations§

§

impl Clone for TimestampId

§

fn clone(&self) -> TimestampId

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 TimestampId

§

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

Formats the value using the given formatter. Read more
§

impl Display for TimestampId

§

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

Formats the TimestampId as a string.

The format is: YYYYMMDDTHHMMSS.mmmZ-<uuid>

Where the UUID is rendered in standard hyphenated format (8-4-4-4-12) for better readability compared to VPR’s canonical unhyphenated UUID format.

§

impl FromStr for TimestampId

§

fn from_str(s: &str) -> Result<TimestampId, <TimestampId as FromStr>::Err>

Parses a TimestampId from its string representation.

The string must be in the format: YYYYMMDDTHHMMSS.mmmZ-<uuid>

§Format Requirements
  • Timestamp part must end with ‘Z’ (UTC timezone indicator)
  • Must contain a hyphen separator between timestamp and UUID
  • Timestamp must be valid (no invalid dates like Feb 30)
  • UUID must be in standard hyphenated format (8-4-4-4-12)
§Arguments
  • s - String slice to parse
§Returns
  • Ok(TimestampId) - Successfully parsed identifier
  • Err(UuidError::InvalidInput) - If the format is invalid
§Errors

Returns [UuidError::InvalidInput] if:

  • The string doesn’t contain a hyphen separator
  • The timestamp doesn’t end with ‘Z’
  • The timestamp format is invalid (e.g., “20260199” for invalid day)
  • The UUID is malformed
§

type Err = UuidError

The associated error which can be returned from parsing.
§

impl Hash for TimestampId

§

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 TimestampId

§

fn eq(&self, other: &TimestampId) -> 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 TimestampId

§

impl StructuralPartialEq for TimestampId

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