Trait cqrs_es::DomainEvent

source ·
pub trait DomainEvent: Serialize + DeserializeOwned + Clone + PartialEq + Debug + Sync + Send {
    // Required methods
    fn event_type(&self) -> String;
    fn event_version(&self) -> String;
}
Expand description

A DomainEvent represents any business change in the state of an Aggregate. DomainEvents are immutable, and when event sourcing is used they are the single source of truth.

The name of a DomainEvent should always be in the past tense, e.g.,

  • AdminPrivilegesGranted
  • EmailAddressChanged
  • DependencyAdded

To simplify serialization, an event should be an enum, and each variant should carry any important information.

Though the DomainEvent trait only has a single function, the events must also derive a number of standard traits.

  • Clone - events may be cloned throughout the framework, particularly when applied to queries
  • Serialize and Deserialize - required for persistence
  • PartialEq and Debug - needed for effective testing

§Examples

#[derive(Clone,Debug,Serialize,Deserialize,PartialEq)]
pub enum CustomerEvent {
    NameChanged{ changed_name: String },
    EmailUpdated{ new_email: String },
}

Required Methods§

source

fn event_type(&self) -> String

A name specifying the event, used for event upcasting.

source

fn event_version(&self) -> String

A version of the event_type, used for event upcasting.

Object Safety§

This trait is not object safe.

Implementors§