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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! The publish builder's entry points on a bare [`Publisher`].
use Future;
use crate::;
use ;
use UnnamedCodec;
use ;
/// The publish builder on any [`Publisher`]: `message(..)`, the one entry point of a publish.
///
/// Blanket-implemented for every publisher, so a broker publisher held in the application state
/// publishes through the same builder as an [`Out`](crate::runtime::Out) slot. The difference is
/// the codec ladder: a bare publisher carries no codec of its own, so `message(..)` encodes with
/// the crate's [`DefaultCodec`](crate::codec::DefaultCodec) unless the call names one with
/// `with_codec(..)`. A surface that has a codec (an `Out` slot, a transaction scope opened on
/// one) shadows this entry point with its own and uses that codec instead.
///
/// One entry point covers both wires. A `serde::Serialize` value takes the resolved codec; a
/// [`Serialized`](super::Serialized) value carries its own bytes and no codec runs on them, which
/// is how a payload that is not a model of its own still travels as a declared type.
///
/// # Examples
///
/// ```
/// # #[cfg(all(feature = "macros", feature = "memory", feature = "json"))]
/// # mod demo {
/// use ruststream::memory::prelude::*;
/// use serde::Serialize;
///
/// #[derive(Serialize, Outgoing)]
/// #[outgoing(name = "services.started")]
/// struct Started {
/// service: &'static str,
/// }
///
/// /// Declares no destination, so the call site names one.
/// #[derive(Serialize, Outgoing)]
/// struct Seeded {
/// rows: u64,
/// }
///
/// fn app() -> RustStream {
/// RustStream::new(AppInfo::new("catalog", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
/// // The hook is handed the live publisher; `message(..)` is the same builder an `Out`
/// // slot offers, encoding with the default codec.
/// b.after_startup(Publish, async move |publisher| {
/// publisher
/// .message(&Seeded { rows: 1200 })
/// .to("catalog.seeded")
/// .publish()
/// .await?;
/// publisher
/// .message(&Started { service: "catalog" })
/// .publish()
/// .await
/// });
/// })
/// }
/// # }
/// # fn main() {}
/// ```