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
use IEvent;
/// Event handlers are usually the aggregates. It applies the
/// events to its state.
///
/// # Example
///
/// For illustration only:
///
/// ```rust
/// use cqrs_es2::{
/// example_impl::CustomerEvent,
/// IEventHandler,
/// };
///
/// pub struct CustomerEventHandler {
/// pub name: String,
/// pub email: String,
/// pub addresses: Vec<String>,
/// };
///
/// impl IEventHandler<CustomerEvent> for CustomerEventHandler {
/// fn apply(
/// &mut self,
/// event: &CustomerEvent,
/// ) {
/// match event {
/// CustomerEvent::NameAdded(payload) => {
/// self.name = payload.changed_name.clone();
/// },
/// CustomerEvent::EmailUpdated(payload) => {
/// self.email = payload.new_email.clone();
/// },
/// CustomerEvent::AddressUpdated(payload) => {
/// self.addresses
/// .push(payload.new_address.clone())
/// },
/// }
/// }
/// }
/// ```