Trait cqrs_es2::IEvent [−][src]
Expand description
An IEvent
represents any business change in the state of an
Aggregate
. IEvent
s are immutable and with
event sourcing
they are the source of truth.
The name of an IEvent
should always be in the past tense,
e.g.,
AdminPrivilegesGranted
EmailAddressChanged
DependencyAdded
To simplify serialization, an event should be an enum, and each element should have a payload. By convention, the payload has the same name as the element, and elements that do not require additional information use an empty payload.
Though the IEvent
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 queriesSerialize
andDeserialize
- required for persistencePartialEq
andDebug
- needed for effective testing
Examples
use serde::{ Deserialize, Serialize, }; use std::fmt::Debug; use cqrs_es2::IEvent; #[derive( Debug, PartialEq, Clone, Serialize, Deserialize )] pub enum CustomerEvent { NameAdded(NameAdded), EmailUpdated(EmailUpdated), } #[derive( Debug, PartialEq, Clone, Serialize, Deserialize )] pub struct NameAdded { changed_name: String, } #[derive( Debug, PartialEq, Clone, Serialize, Deserialize )] pub struct EmailUpdated { new_email: String, } impl IEvent for CustomerEvent {};