pub struct DomainEvent<T> {
pub event_id: Uuid,
pub payload: T,
pub occurred_at: DateTime<Utc>,
pub version: u64,
pub correlation_id: Option<Uuid>,
pub causation_id: Option<Uuid>,
pub metadata: HashMap<String, String>,
}Expand description
Generic domain event wrapper that provides consistent event metadata
This is the core event type that wraps all domain events in the system. It provides standardized metadata, correlation tracking, and serialization capabilities for event sourcing and distributed tracing.
§Type Parameters
T- The event payload type that contains the specific event data
§Features
- Event Identification: Unique UUID for each event instance
- Timestamp Management: RFC3339 formatted timestamps for precise ordering
- Schema Versioning: Version tracking for event schema evolution
- Correlation Tracking: Distributed tracing with correlation and causation IDs
- Metadata Support: Extensible metadata for additional context
- Serialization: Full JSON serialization/deserialization support
§Examples
Fields§
§event_id: UuidUnique identifier for this event instance
payload: TThe specific event payload containing event-specific data
occurred_at: DateTime<Utc>When this event occurred (RFC3339 format for consistency)
version: u64Event schema version for evolution support
correlation_id: Option<Uuid>Optional correlation ID for tracing related events
causation_id: Option<Uuid>Optional causation ID (the event that caused this event)
metadata: HashMap<String, String>Event metadata for additional context
Implementations§
Source§impl<T> DomainEvent<T>
impl<T> DomainEvent<T>
Sourcepub fn new_with_correlation(
payload: T,
correlation_id: Option<Uuid>,
causation_id: Option<Uuid>,
) -> Self
pub fn new_with_correlation( payload: T, correlation_id: Option<Uuid>, causation_id: Option<Uuid>, ) -> Self
Sourcepub fn new_with_version(payload: T, version: u64) -> Self
pub fn new_with_version(payload: T, version: u64) -> Self
Sourcepub fn with_metadata(self, key: String, value: String) -> Self
pub fn with_metadata(self, key: String, value: String) -> Self
Sourcepub fn with_correlation_id(self, correlation_id: Uuid) -> Self
pub fn with_correlation_id(self, correlation_id: Uuid) -> Self
Sourcepub fn with_causation_id(self, causation_id: Uuid) -> Self
pub fn with_causation_id(self, causation_id: Uuid) -> Self
Sourcepub fn event_type(&self) -> &'static str
pub fn event_type(&self) -> &'static str
Trait Implementations§
Source§impl<T: Clone> Clone for DomainEvent<T>
impl<T: Clone> Clone for DomainEvent<T>
Source§fn clone(&self) -> DomainEvent<T>
fn clone(&self) -> DomainEvent<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for DomainEvent<T>
impl<T: Debug> Debug for DomainEvent<T>
Source§impl<'de, T> Deserialize<'de> for DomainEvent<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for DomainEvent<T>where
T: Deserialize<'de>,
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for DomainEvent<T>where
T: Freeze,
impl<T> RefUnwindSafe for DomainEvent<T>where
T: RefUnwindSafe,
impl<T> Send for DomainEvent<T>where
T: Send,
impl<T> Sync for DomainEvent<T>where
T: Sync,
impl<T> Unpin for DomainEvent<T>where
T: Unpin,
impl<T> UnwindSafe for DomainEvent<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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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