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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! Stable message contract identity (ADR 0010).
use fmt;
use Cow;
/// A type that can be built into an [`Envelope`](crate::Envelope) and persisted or published.
///
/// `TYPE`/`VERSION` are stable **application contracts**: they identify a message across
/// serialization, storage and the wire, and are never derived from
/// `std::any::type_name::<T>()` or a module path — renaming or moving the Rust type must not
/// orphan a pending row or a message already in flight (ADR 0010).
///
/// ```
/// use reliar_core::Message;
///
/// #[derive(serde::Serialize, serde::Deserialize)]
/// struct OrderCancelled {
/// order_id: u64,
/// }
///
/// impl Message for OrderCancelled {
/// const TYPE: &'static str = "orders.cancelled";
/// const VERSION: u16 = 1;
/// }
///
/// assert_eq!(OrderCancelled::TYPE, "orders.cancelled");
/// assert_eq!(OrderCancelled::VERSION, 1);
/// ```
/// A message's name and version, carried separately so a query can filter a name across every
/// version. Renders as `"{name}.v{version}"` via its [`Display`](fmt::Display) impl.
///
/// ```
/// use reliar_core::{Message, MessageType};
///
/// #[derive(serde::Serialize, serde::Deserialize)]
/// struct OrderCreated;
/// impl Message for OrderCreated {
/// const TYPE: &'static str = "orders.created";
/// const VERSION: u16 = 1;
/// }
///
/// let message_type = MessageType::of::<OrderCreated>();
/// assert_eq!(message_type.name(), "orders.created");
/// assert_eq!(message_type.version(), 1);
/// assert_eq!(message_type.to_string(), "orders.created.v1");
/// ```
/// Renders `"{name}.v{version}"`, e.g. `orders.created.v1`. **A stable public contract**:
/// clients parse this string. Two distinct Rust types sharing `TYPE`/`VERSION` render
/// identically — that is intended, not a bug (ADR 0010).