Skip to main content

Event

Struct Event 

Source
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: i64

Implementations§

Source§

impl Event

Source

pub fn new( event_type: EventType, entity_id: EntityId, tenant_id: TenantId, payload: Value, ) -> Self

Create a new Event with value objects (recommended)

Source

pub fn with_metadata( event_type: EventType, entity_id: EntityId, tenant_id: TenantId, payload: Value, metadata: Value, ) -> Self

Create event with optional metadata

Source

pub fn with_default_tenant( event_type: EventType, entity_id: EntityId, payload: Value, ) -> Self

Create event with default tenant (for single-tenant use)

Source

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.

Source

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)

Source

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)

Source

pub fn id(&self) -> Uuid

Source

pub fn event_type(&self) -> &EventType

Source

pub fn event_type_str(&self) -> &str

Source

pub fn entity_id(&self) -> &EntityId

Source

pub fn entity_id_str(&self) -> &str

Source

pub fn tenant_id(&self) -> &TenantId

Source

pub fn tenant_id_str(&self) -> &str

Source

pub fn payload(&self) -> &Value

Source

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

Source

pub fn metadata(&self) -> Option<&Value>

Source

pub fn version(&self) -> i64

Source

pub fn belongs_to_tenant(&self, tenant_id: &TenantId) -> bool

Check if this event belongs to a specific tenant

Source

pub fn belongs_to_tenant_str(&self, tenant_id: &str) -> bool

Check if this event belongs to a tenant (by string)

Source

pub fn relates_to_entity(&self, entity_id: &EntityId) -> bool

Check if this event relates to a specific entity

Source

pub fn relates_to_entity_str(&self, entity_id: &str) -> bool

Check if this event relates to an entity (by string)

Source

pub fn is_type(&self, event_type: &EventType) -> bool

Check if this event is of a specific type

Source

pub fn is_type_str(&self, event_type: &str) -> bool

Check if this event is of a type (by string)

Source

pub fn is_in_namespace(&self, namespace: &str) -> bool

Check if this event is in a specific namespace

Source

pub fn occurred_between(&self, start: DateTime<Utc>, end: DateTime<Utc>) -> bool

Check if this event occurred within a time range

Source

pub fn occurred_before(&self, time: DateTime<Utc>) -> bool

Check if event occurred before a specific time

Source

pub fn occurred_after(&self, time: DateTime<Utc>) -> bool

Check if event occurred after a specific time

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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
Source§

impl Debug for Event

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Event

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&Event> for EventDto

Source§

fn from(event: &Event) -> Self

Converts to this type from the input type.
Source§

impl From<&Event> for EventSummary

Source§

fn from(event: &Event) -> Self

Converts to this type from the input type.
Source§

impl From<Event> for EventDto

Source§

fn from(event: Event) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> 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.
Source§

impl Serialize for Event

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,