pub struct Event {
pub id: Uuid,
pub event_type: EventType,
pub entity_id: EntityId,
pub tenant_id: TenantId,
pub payload: Value,
pub timestamp: DateTime<Utc>,
pub metadata: Option<Value>,
pub version: i64,
}Expand description
Domain Entity: Event
Core event structure representing a domain event in the event store. This is an immutable, timestamped record of something that happened.
Domain Rules:
- Events are immutable once created
- Event type must follow naming convention (enforced by EventType value object)
- Entity ID cannot be empty (enforced by EntityId value object)
- Tenant ID cannot be empty (enforced by TenantId value object)
- Timestamp must not be in the future
- Version starts at 1
Fields§
§id: Uuid§event_type: EventType§entity_id: EntityId§tenant_id: TenantId§payload: Value§timestamp: DateTime<Utc>§metadata: Option<Value>§version: i64Implementations§
Source§impl Event
impl Event
Sourcepub fn new(
event_type: EventType,
entity_id: EntityId,
tenant_id: TenantId,
payload: Value,
) -> Self
pub fn new( event_type: EventType, entity_id: EntityId, tenant_id: TenantId, payload: Value, ) -> Self
Create a new Event with value objects (recommended)
Sourcepub fn with_metadata(
event_type: EventType,
entity_id: EntityId,
tenant_id: TenantId,
payload: Value,
metadata: Value,
) -> Self
pub fn with_metadata( event_type: EventType, entity_id: EntityId, tenant_id: TenantId, payload: Value, metadata: Value, ) -> Self
Create event with optional metadata
Sourcepub fn with_default_tenant(
event_type: EventType,
entity_id: EntityId,
payload: Value,
) -> Self
pub fn with_default_tenant( event_type: EventType, entity_id: EntityId, payload: Value, ) -> Self
Create event with default tenant (for single-tenant use)
Sourcepub fn from_strings(
event_type: String,
entity_id: String,
tenant_id: String,
payload: Value,
metadata: Option<Value>,
) -> Result<Self>
pub fn from_strings( event_type: String, entity_id: String, tenant_id: String, payload: Value, metadata: Option<Value>, ) -> Result<Self>
Create event from strings (for backward compatibility)
This validates the strings and creates value objects. Use the value object constructor for new code.
Sourcepub fn reconstruct(
id: Uuid,
event_type: EventType,
entity_id: EntityId,
tenant_id: TenantId,
payload: Value,
timestamp: DateTime<Utc>,
metadata: Option<Value>,
version: i64,
) -> Self
pub fn reconstruct( id: Uuid, event_type: EventType, entity_id: EntityId, tenant_id: TenantId, payload: Value, timestamp: DateTime<Utc>, metadata: Option<Value>, version: i64, ) -> Self
Reconstruct an Event from storage (bypasses validation for stored events)
Sourcepub fn reconstruct_from_strings(
id: Uuid,
event_type: String,
entity_id: String,
tenant_id: String,
payload: Value,
timestamp: DateTime<Utc>,
metadata: Option<Value>,
version: i64,
) -> Self
pub fn reconstruct_from_strings( id: Uuid, event_type: String, entity_id: String, tenant_id: String, payload: Value, timestamp: DateTime<Utc>, metadata: Option<Value>, version: i64, ) -> Self
Reconstruct from raw strings (for loading from old storage)
pub fn id(&self) -> Uuid
pub fn event_type(&self) -> &EventType
pub fn event_type_str(&self) -> &str
pub fn entity_id(&self) -> &EntityId
pub fn entity_id_str(&self) -> &str
pub fn tenant_id(&self) -> &TenantId
pub fn tenant_id_str(&self) -> &str
pub fn payload(&self) -> &Value
pub fn timestamp(&self) -> DateTime<Utc>
pub fn metadata(&self) -> Option<&Value>
pub fn version(&self) -> i64
Sourcepub fn belongs_to_tenant(&self, tenant_id: &TenantId) -> bool
pub fn belongs_to_tenant(&self, tenant_id: &TenantId) -> bool
Check if this event belongs to a specific tenant
Sourcepub fn belongs_to_tenant_str(&self, tenant_id: &str) -> bool
pub fn belongs_to_tenant_str(&self, tenant_id: &str) -> bool
Check if this event belongs to a tenant (by string)
Sourcepub fn relates_to_entity(&self, entity_id: &EntityId) -> bool
pub fn relates_to_entity(&self, entity_id: &EntityId) -> bool
Check if this event relates to a specific entity
Sourcepub fn relates_to_entity_str(&self, entity_id: &str) -> bool
pub fn relates_to_entity_str(&self, entity_id: &str) -> bool
Check if this event relates to an entity (by string)
Sourcepub fn is_type(&self, event_type: &EventType) -> bool
pub fn is_type(&self, event_type: &EventType) -> bool
Check if this event is of a specific type
Sourcepub fn is_type_str(&self, event_type: &str) -> bool
pub fn is_type_str(&self, event_type: &str) -> bool
Check if this event is of a type (by string)
Sourcepub fn is_in_namespace(&self, namespace: &str) -> bool
pub fn is_in_namespace(&self, namespace: &str) -> bool
Check if this event is in a specific namespace
Sourcepub fn occurred_between(&self, start: DateTime<Utc>, end: DateTime<Utc>) -> bool
pub fn occurred_between(&self, start: DateTime<Utc>, end: DateTime<Utc>) -> bool
Check if this event occurred within a time range
Sourcepub fn occurred_before(&self, time: DateTime<Utc>) -> bool
pub fn occurred_before(&self, time: DateTime<Utc>) -> bool
Check if event occurred before a specific time
Sourcepub fn occurred_after(&self, time: DateTime<Utc>) -> bool
pub fn occurred_after(&self, time: DateTime<Utc>) -> bool
Check if event occurred after a specific time
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Event
impl<'de> Deserialize<'de> for Event
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 From<&Event> for EventSummary
impl From<&Event> for EventSummary
impl StructuralPartialEq for Event
Auto Trait Implementations§
impl Freeze for Event
impl RefUnwindSafe for Event
impl Send for Event
impl Sync for Event
impl Unpin for Event
impl UnwindSafe for Event
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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