1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use ;
use Debug;
/// An `IEvent` represents any business change in the state of an
/// `Aggregate`. `IEvent`s are immutable and with
/// [event sourcing](https://martinfowler.com/eaaDev/EventSourcing.html)
/// 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 queries
/// - `Serialize` and `Deserialize` - required for persistence
/// - `PartialEq` and `Debug` - needed for effective testing
///
/// # Examples
/// ```rust
/// 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 {};
/// ```