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 separatorHHMMSS- 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
PartialEqandEqfor 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
TimestampIdGeneratorfor 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
- Use
TimestampId::newwhen you already have a timestamp and UUID - Use
FromStrorTimestampId::from_strto parse a string representation - Use
TimestampIdGenerator::generateto create new IDs with monotonicity guarantees
§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
TimestampIdGenerator- For generating new IDs with monotonicityUuid- For the UUID component
Implementations§
§impl TimestampId
impl TimestampId
pub fn new(timestamp: DateTime<Utc>, uuid: Uuid) -> 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 identifieruuid- The unique identifier component
§Returns
A new TimestampId with the specified components.
pub fn timestamp(&self) -> DateTime<Utc>
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>.
Trait Implementations§
§impl Clone for TimestampId
impl Clone for TimestampId
§fn clone(&self) -> TimestampId
fn clone(&self) -> TimestampId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for TimestampId
impl Debug for TimestampId
§impl Display for TimestampId
impl Display for TimestampId
§impl FromStr for TimestampId
impl FromStr for TimestampId
§fn from_str(s: &str) -> Result<TimestampId, <TimestampId as FromStr>::Err>
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 identifierErr(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
§impl Hash for TimestampId
impl Hash for TimestampId
§impl PartialEq for TimestampId
impl PartialEq for TimestampId
impl Eq for TimestampId
impl StructuralPartialEq for TimestampId
Auto Trait Implementations§
impl Freeze for TimestampId
impl RefUnwindSafe for TimestampId
impl Send for TimestampId
impl Sync for TimestampId
impl Unpin for TimestampId
impl UnwindSafe for TimestampId
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