pub struct GenericId<T: IdCategory> { /* private fields */ }Expand description
Generic identifier value object for domain entities
§Purpose
Provides the foundational ID implementation that all specific entity IDs build upon. This generic approach ensures consistency while allowing type-safe specialization.
§Design Principles
- Type Safety: Each entity gets its own distinct ID type
- Validation: Consistent validation rules across all ID types
- Serialization: Uniform JSON/database representation
- Cross-Language: Clear specification for Go implementation
§Architecture Notes
This is the base implementation that specific ID value objects compose.
It should not be used directly - instead use the specific ID types like
PipelineId, StageId, etc.
§Cross-Language Mapping
- Rust:
GenericId<T>with phantom type parameter - Go:
GenericID[T any]with type parameter - JSON: String representation of ULID
- SQLite: TEXT column with ULID string
- Time-Ordered: Natural chronological sorting
Implementations§
Source§impl<T: IdCategory> GenericId<T>
impl<T: IdCategory> GenericId<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new time-ordered entity ID with category validation
§Time Ordering
ULIDs are naturally sorted by creation time, making them perfect for:
- Database indexes (sequential inserts)
- Event ordering
- Chronological queries
- Debugging (time-based ID inspection)
Sourcepub fn from_ulid(ulid: Ulid) -> Result<Self, PipelineError>
pub fn from_ulid(ulid: Ulid) -> Result<Self, PipelineError>
Creates an entity ID from an existing ULID with validation
Sourcepub fn from_timestamp_ms(timestamp_ms: u64) -> Result<Self, PipelineError>
pub fn from_timestamp_ms(timestamp_ms: u64) -> Result<Self, PipelineError>
Creates an entity ID from a timestamp (useful for range queries)
§Use Cases
- Creating boundary IDs for time-range queries
- Testing with specific timestamps
- Migration scenarios requiring specific timestamp IDs
Sourcepub fn from_string(s: &str) -> Result<Self, PipelineError>
pub fn from_string(s: &str) -> Result<Self, PipelineError>
Creates an entity ID from a string representation
§Format
Accepts standard ULID string format (26 characters, base32 encoded) Example: “01ARZ3NDEKTSV4RRFFQ69G5FAV”
Sourcepub fn timestamp_ms(&self) -> u64
pub fn timestamp_ms(&self) -> u64
Sourcepub fn datetime(&self) -> DateTime<Utc>
pub fn datetime(&self) -> DateTime<Utc>
Gets the creation time as a DateTime
§Use Cases
- Human-readable timestamps
- Time-based filtering
- Audit logs
Sourcepub fn to_lowercase(&self) -> String
pub fn to_lowercase(&self) -> String
Converts to lowercase string representation
§Use Cases
- Case-insensitive systems
- URL paths
- Database systems that prefer lowercase
Sourcepub fn validate(&self) -> Result<(), PipelineError>
pub fn validate(&self) -> Result<(), PipelineError>
Validates the ID using category-specific rules
Trait Implementations§
Source§impl<T: IdCategory> Default for GenericId<T>
impl<T: IdCategory> Default for GenericId<T>
Source§impl<'de, T: IdCategory> Deserialize<'de> for GenericId<T>
impl<'de, T: IdCategory> Deserialize<'de> for GenericId<T>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T: IdCategory> Display for GenericId<T>
impl<T: IdCategory> Display for GenericId<T>
Source§impl<T: IdCategory> FromStr for GenericId<T>
impl<T: IdCategory> FromStr for GenericId<T>
Source§impl<T: IdCategory> Hash for GenericId<T>
impl<T: IdCategory> Hash for GenericId<T>
Source§impl<T: Ord + IdCategory> Ord for GenericId<T>
impl<T: Ord + IdCategory> Ord for GenericId<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd + IdCategory> PartialOrd for GenericId<T>
impl<T: PartialOrd + IdCategory> PartialOrd for GenericId<T>
Source§impl<T: IdCategory> Serialize for GenericId<T>
impl<T: IdCategory> Serialize for GenericId<T>
impl<T: Eq + IdCategory> Eq for GenericId<T>
impl<T: IdCategory> StructuralPartialEq for GenericId<T>
Auto Trait Implementations§
impl<T> Freeze for GenericId<T>
impl<T> RefUnwindSafe for GenericId<T>where
T: RefUnwindSafe,
impl<T> Send for GenericId<T>where
T: Send,
impl<T> Sync for GenericId<T>where
T: Sync,
impl<T> Unpin for GenericId<T>where
T: Unpin,
impl<T> UnwindSafe for GenericId<T>where
T: UnwindSafe,
Blanket Implementations§
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,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more