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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//! Pure, typed actor-behavior primitives.
//!
//! [`Protocol`] is stable public destination identity (`Addr` plus `Msg`). A
//! [`Behavior`] separately owns state and folds its complete [`Behavior::Event`]
//! algebra into exactly [`Actions`]: sends, fresh creations, and its next
//! behavior or termination. A protocol is not a behavior, and `Behavior` is not
//! a `Protocol` supertrait. Higher capabilities extend internal event and
//! effect algebras while transparent wrappers preserve [`Behavior::Protocol`].
//!
//! Finite mailbox execution belongs to a runtime or test driver, not to this
//! one-turn behavior algebra.
//!
//! ```compile_fail,E0405
//! fn requires_reducer<T: behavior::ActionReducer>() {}
//! ```
//!
//! Capability-restricted action products use the existing `Actions` algebra;
//! there is no second convenience wrapper with an overlapping contract.
//!
//! ```compile_fail
//! fn accepts_duplicate(_: behavior::Effect<u8>) {}
//! ```
// The `#[behavior]` expansion emits `::behavior::…` paths; this alias lets the
// expansion resolve inside this crate too.
extern crate self as behavior;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Generate the nominal protocol, closed effect products, and exact `Behavior`
/// wiring for an inherent impl. `addr` and `message` are required. Omitting
/// `sends`, `births`, or `error` selects the capability-free `NoSends`,
/// `NoBirths`, or `Never` type respectively.
///
/// A `sends = { lane: Product }` declaration generates a module-private
/// `ActorSends`; `sends = pub { lane: Product }` exports it for a public actor.
/// Its lane selectors, settlement product, and fluent trait have the same
/// visibility. Each field contributes its logical-host protocols in declared
/// order, including duplicates, through [`LogicalDeliveryProtocols`]. The
/// product also derives structural `SendEffects`, `SendsFor`,
/// [`SendSettlements`], and `InterpretSends` implementations. The settlement
/// product keeps the same semantic field names and one runtime-independent
/// type. The macro also generates an
/// `ActorActions` extension trait with one fluent `send_lane` method per named
/// lane. Each method delegates to [`AppendSend`], changing only the send leg
/// while preserving creations and the exact next-behavior verdict. A
/// `births = { lane: Child }` declaration generates `ActorChildren` as the
/// exact closed child algebra. One child remains its direct concrete type;
/// multiple alternatives form `ChildChoice` in declaration order. The macro
/// also generates one nominal role per declaration and an `ActorChild`
/// namespace for those roles. Every role implements both [`ChildRole`] for its
/// authored parent and [`ChildOccurrence`] for sealed resolution against that
/// parent or a topology-transparent wrapper. Creation remains an authored
/// [`Creations`] or [`Children`] value and is never performed by the macro.
///
/// Invalid receivers are rejected at compile time.
/// A birth-owning generated actor must also select the exact creation-settlement
/// disposition; there is no implicit discard or generated no-op receiver.
///
/// ```compile_fail
/// struct Child;
/// #[behavior::behavior(addr = behavior::MailAddr, message = behavior::Never)]
/// impl Child {
/// fn receive(
/// &mut self,
/// _: behavior::MailAddr,
/// message: behavior::Never,
/// ) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// struct MissingCreationSettlementDisposition;
/// #[behavior::behavior(
/// addr = behavior::MailAddr,
/// message = behavior::Never,
/// births = { child: Child },
/// )]
/// impl MissingCreationSettlementDisposition {
/// fn receive(
/// &mut self,
/// _: behavior::MailAddr,
/// message: behavior::Never,
/// ) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// ```
///
/// ```compile_fail
///
/// struct Invalid;
/// #[behavior::behavior(
/// addr = behavior::MailAddr,
/// message = u8,
/// )]
/// impl Invalid {
/// fn init(&self) -> behavior::BehaviorActed<Self> {
/// Ok(behavior::Actions::cont())
/// }
/// fn receive(&mut self, _: behavior::MailAddr, _: u8) -> behavior::BehaviorActed<Self> {
/// Ok(behavior::Actions::cont())
/// }
/// }
/// ```
///
/// Missing receive methods are rejected by the macro itself:
///
/// ```compile_fail
/// struct Missing;
/// #[behavior::behavior(
/// addr = behavior::MailAddr,
/// message = u8,
/// )]
/// impl Missing {
/// }
/// ```
///
/// Async behavior methods cannot introduce an erased or alternate execution
/// path:
///
/// ```compile_fail
/// struct Async;
/// #[behavior::behavior(
/// addr = behavior::MailAddr,
/// message = u8,
/// )]
/// impl Async {
/// async fn init(&mut self) -> behavior::BehaviorActed<Self> {
/// Ok(behavior::Actions::cont())
/// }
/// fn receive(&mut self, _: behavior::MailAddr, _: u8) -> behavior::BehaviorActed<Self> {
/// Ok(behavior::Actions::cont())
/// }
/// }
/// ```
///
/// Undeclared send lanes have no selector and cannot be emitted:
///
/// ```compile_fail
/// struct Sender;
/// #[behavior::behavior(addr = behavior::MailAddr, message = (), sends = { replies: Vec<u8> })]
/// impl Sender {
/// fn receive(&mut self, _: behavior::MailAddr, _: ()) -> behavior::BehaviorActed<Self> {
/// let mut sends: SenderSends = behavior::SendEffects::empty();
/// behavior::SendEffects::send::<_, SenderSendsUndeclared>(&mut sends, 1);
/// Ok(behavior::Actions::send(sends))
/// }
/// }
/// ```
///
/// Generated lane methods accept only inputs supported by that lane:
///
/// ```compile_fail
/// struct Sender;
/// #[behavior::behavior(addr = behavior::MailAddr, message = (), sends = { replies: Vec<u8> })]
/// impl Sender {
/// fn receive(&mut self, _: behavior::MailAddr, _: ()) -> behavior::BehaviorActed<Self> {
/// Ok(behavior::Actions::cont().send_replies("not a u8"))
/// }
/// }
/// ```
///
/// A child absent from the declared closed birth product cannot be created:
///
/// ```compile_fail
/// struct Declared;
/// #[behavior::behavior(addr = behavior::MailAddr, message = behavior::Never)]
/// impl Declared {
/// fn receive(&mut self, _: behavior::MailAddr, message: behavior::Never) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// struct Other;
/// #[behavior::behavior(addr = behavior::MailAddr, message = behavior::Never)]
/// impl Other {
/// fn receive(&mut self, _: behavior::MailAddr, message: behavior::Never) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// struct Root { creations: behavior::CreationSequence }
/// #[behavior::behavior(
/// addr = behavior::MailAddr,
/// message = (),
/// births = { declared: Declared },
/// creation_settlements = retain_for_retirement,
/// )]
/// impl Root {
/// fn receive(&mut self, _: behavior::MailAddr, _: ()) -> behavior::BehaviorActed<Self> {
/// let id = self.creations.issue().expect("fixture creation ID");
/// Ok(behavior::Actions::create(behavior::Creations::one(behavior::CreateChild::birth(id, Other))))
/// }
/// }
/// ```
///
/// Every generated send lane remains a separate interpreter obligation:
///
/// ```compile_fail
/// struct Root;
/// type AuditProtocol = behavior::MessageProtocol<behavior::MailAddr, u8>;
/// type MetricsProtocol = behavior::MessageProtocol<behavior::MailAddr, u16>;
/// #[behavior::behavior(addr = behavior::MailAddr, message = (), sends = {
/// audit: Vec<behavior::Delivery<AuditProtocol>>,
/// metrics: Vec<behavior::Delivery<MetricsProtocol>>,
/// })]
/// impl Root {
/// fn receive(&mut self, _: behavior::MailAddr, _: ()) -> behavior::BehaviorActed<Self> {
/// Ok(behavior::Actions::cont())
/// }
/// }
/// struct Incomplete;
/// impl<RootEvent, Path> behavior::InterpretItem<behavior::Delivery<AuditProtocol>, RootEvent, Path> for Incomplete {
/// fn interpret_item<'a>(&'a mut self, input: &'a mut Option<behavior::Delivery<AuditProtocol>>, received: &'a mut Option<<behavior::Delivery<AuditProtocol> as behavior::ActionItem>::Reply>) -> impl core::future::Future<Output = ()> + Send + 'a where behavior::Delivery<AuditProtocol>: 'a {
/// async move {
/// if received.is_some() { return; }
/// let Some(delivery) = input.take() else { return; };
/// drop(delivery);
/// *received = Some(behavior::ItemSettlement::Accepted(()));
/// }
/// }
/// }
/// fn require_complete()
/// where
/// RootSends: behavior::InterpretSends<Incomplete, behavior::User<behavior::MailAddr, ()>, behavior::Here>,
/// {}
/// ```
///
/// Generated child products likewise require one [`EstablishChild`]
/// implementation for every declared alternative. [`DispatchBirth`] owns the
/// compile-denial example so this crate overview does not duplicate it.
///
/// Two declared roles remain distinct even when they use the same behavior:
///
/// ```compile_fail
/// struct Worker;
/// #[behavior::behavior(addr = behavior::MailAddr, message = ())]
/// impl Worker {
/// fn receive(&mut self, _: behavior::MailAddr, _: ()) -> behavior::BehaviorActed<Self> {
/// Ok(behavior::Actions::cont())
/// }
/// }
/// struct Root;
/// #[behavior::behavior(addr = behavior::MailAddr, message = behavior::Never, births = {
/// primary: Worker,
/// backup: Worker,
/// }, creation_settlements = retain_for_retirement)]
/// impl Root {
/// fn receive(&mut self, _: behavior::MailAddr, message: behavior::Never) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// fn requires_primary(
/// _: behavior::ChildDelivery<<Worker as behavior::Behavior>::Protocol, RootChildrenPrimary>,
/// ) {}
/// let mut sequence = behavior::CreationSequence::new();
/// let id = sequence.issue().expect("fixture creation ID");
/// let backup = behavior::ChildDelivery::<<Worker as behavior::Behavior>::Protocol, RootChildrenBackup>::after(id, ());
/// requires_primary(backup);
/// ```
///
/// Named topology selectors accept only the child declared for that parent
/// role, which lets an application builder remain entirely static:
///
/// ```compile_fail
/// struct Worker;
/// #[behavior::behavior(addr = behavior::MailAddr, message = behavior::Never)]
/// impl Worker {
/// fn receive(&mut self, _: behavior::MailAddr, message: behavior::Never) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// struct Query;
/// #[behavior::behavior(addr = behavior::MailAddr, message = behavior::Never)]
/// impl Query {
/// fn receive(&mut self, _: behavior::MailAddr, message: behavior::Never) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// struct Root;
/// #[behavior::behavior(
/// addr = behavior::MailAddr,
/// message = behavior::Never,
/// births = { workers: Worker },
/// creation_settlements = retain_for_retirement,
/// )]
/// impl Root {
/// fn receive(&mut self, _: behavior::MailAddr, message: behavior::Never) -> behavior::BehaviorActed<Self> {
/// match message {}
/// }
/// }
/// fn child<Parent, Role>(_: Role, _: Role::Child)
/// where
/// Parent: behavior::Behavior,
/// Role: behavior::ChildRole<Parent>,
/// {}
/// child::<Root, _>(RootChild::Workers, Query);
/// ```
pub use behavior;