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 Serialize;
use DeserializeOwned;
use fmt;
use crateVersion;
/// Capability bound that every domain event payload must satisfy.
///
/// A `DomainEvent` is a fact — an immutable record of something that has
/// happened inside an aggregate. Implementations are typically `enum`s with
/// one variant per concrete event, generated by the `#[domain_event]`
/// procedural macro. The auto-generated implementation handles identity,
/// type discrimination and version tagging so application code can focus on
/// the business payload of each variant.
///
/// # Trait bounds
///
/// The supertrait set is intentionally broad and covers the practical
/// requirements of an event-sourced system:
///
/// - `Clone` + `PartialEq` + `Debug` make events convenient to assert against
/// in tests and to fan out to multiple consumers.
/// - `Serialize` + `DeserializeOwned` enable round-tripping through the
/// persistence layer (see [`crate::persist::SerializedEvent`]) and any
/// transport boundary (message bus, HTTP, etc.).
/// - `Send` + `Sync` + `'static` allow events to flow freely across async
/// tasks and thread boundaries.
///
/// # Contract
///
/// Implementations must guarantee:
///
/// - [`event_id`](Self::event_id) is globally unique for the lifetime of the
/// system. It is used for idempotency, deduplication and as the
/// `causation_id` of any downstream event.
/// - [`event_type`](Self::event_type) is a stable string identifier. Renaming
/// a variant is a breaking change for stored data and must be handled via
/// an [`EventUpcaster`](crate::event_upcaster::EventUpcaster).
/// - [`event_version`](Self::event_version) starts at `1` and is bumped only
/// when the payload schema of that variant changes.
/// - [`aggregate_version`](Self::aggregate_version) is the version of the
/// owning aggregate **after** this event has been applied. It is the value
/// the persistence layer uses for optimistic concurrency control.