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
use crate;
/// What happens to the frame that [`Processor::decide_data`] or
/// [`Processor::decide_system`] just received.
/// Outcome of [`Processor::decide_data`] / [`Processor::decide_system`]:
/// a disposition for the input frame plus zero or more effects to emit.
///
/// # Four forms
///
/// ```
/// use pipecrab_core::{Decision, Disposition};
///
/// // 1. Pass-through: forward the input, emit nothing.
/// let d: Decision<u32> = Decision::forward();
/// assert_eq!(d.disposition, Disposition::Forward);
/// assert!(d.effects.is_empty());
///
/// // 2. Transform (drop-on-emit): consume the input, emit a replacement.
/// let d: Decision<u32> = Decision::drop().emit(42);
/// assert_eq!(d.disposition, Disposition::Drop);
/// assert_eq!(d.effects, [42]);
///
/// // 3. Observe-and-pass: forward the input *and* emit a derived value.
/// let d: Decision<u32> = Decision::forward().emit(42);
/// assert_eq!(d.disposition, Disposition::Forward);
/// assert_eq!(d.effects, [42]);
///
/// // 4. Silent drop: consume the input, emit nothing.
/// let d: Decision<u32> = Decision::drop();
/// assert_eq!(d.disposition, Disposition::Drop);
/// assert!(d.effects.is_empty());
/// ```
/// The pure core of a stage.
///
/// Both methods are synchronous and total — no `.await`, no I/O — so they
/// cannot be cancelled mid-step. All state mutation happens here; `perform`
/// (in the runtime) is `&self` so a dropped future can't tear state.
///
/// `Effect` is the stage's own command vocabulary: plain data defined in core.
/// The methods emit commands describing *what should happen*; the runtime's
/// `perform` interprets them and does the I/O.
///
/// # Control calls
///
/// "No I/O" has one carve-out. `decide_*` may issue *control calls*:
/// synchronous, non-blocking, idempotent, infallible operations on owned
/// engines. The canonical example is `cancel()`, which flips an atomic flag an
/// engine's worker observes; it cannot block, fail, allocate unboundedly, or
/// tear state, so invoking it from the synchronous, `&mut self` decide step is
/// sound. Anything that can block, fail, allocate unboundedly, or perform real
/// I/O is *not* a control call — it remains an [`Effect`](Processor::Effect)
/// for `perform` to carry out.
///
/// # Defaults
///
/// Both methods default to [`Decision::forward()`]: an un-overridden stage is a
/// transparent pass-through. Override only the variants you care about.