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
use crateICommand;
use ;
/// Event consumers are usually the queries. It updates its state with
/// the emitted events.
///
/// # Example
///
/// For illustration only:
///
/// ```rust
/// use cqrs_es2::{
/// example_impl::{
/// CustomerCommand,
/// CustomerEvent,
/// },
/// EventContext,
/// IEventConsumer,
/// };
///
/// pub struct CustomerEventConsumer {
/// pub name: String,
/// pub email: String,
/// pub latest_address: String,
/// };
///
/// impl IEventConsumer<CustomerCommand, CustomerEvent>
/// for CustomerEventConsumer
/// {
/// fn update(
/// &mut self,
/// event: &EventContext<CustomerCommand, CustomerEvent>,
/// ) {
/// match &event.payload {
/// CustomerEvent::NameAdded(payload) => {
/// self.name = payload.changed_name.clone();
/// },
/// CustomerEvent::EmailUpdated(payload) => {
/// self.email = payload.new_email.clone();
/// },
/// CustomerEvent::AddressUpdated(payload) => {
/// self.latest_address = payload.new_address.clone();
/// },
/// }
/// }
/// }
/// ```