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
use ;
/// Captures a "before" and "after" pair for a single field of a domain event.
///
/// `FieldChanged<T>` is the canonical way to model field-level updates in an
/// event payload. Storing both the previous and new value alongside each
/// other has two benefits:
///
/// - it keeps events self-describing — projections and read-side handlers do
/// not have to query historical state to know what changed;
/// - it makes "no-op" updates trivial to detect via [`is_changed`](Self::is_changed)
/// when `T: PartialEq`.
///
/// # Examples
///
/// ```ignore
/// // Inside a domain event variant
/// pub struct ShippingAddressUpdated {
/// pub address: FieldChanged<Address>,
/// }
///
/// // Constructing one from old and new values
/// let change = FieldChanged::new(old_address, new_address);
/// if change.is_changed() {
/// // emit the event ...
/// }
/// ```