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
//! The file transport's typed contexts and their compile-time keys.
//!
//! A stream file is a replayable log, so a handler running on it can reposition its own
//! subscription. The delivery's position and the subscription's reposition handle travel as
//! fields of a context the runtime builds per delivery, and handlers read them by key -
//! [`Ctx`](ruststream::runtime::Ctx) on the attribute path, `ctx.context(..)` on the manual one.
//!
//! Standard input has no retained log, so nothing here applies to it: its deliveries carry no
//! reposition handle, which is what makes a stdio mount of a seeking handler a compile error.
use ;
use crateFilePosition;
use crate;
/// The file transport's per-delivery context: this delivery's position in the stream file, and
/// the subscription's own seeker.
///
/// The runtime builds one per delivery, and handlers read its fields by key - [`Position`] and
/// [`SeekHandle`]. A body that repositions a stream file names this type as its context axis and
/// needs nothing else.
///
/// # Examples
///
/// ```
/// use ruststream::prelude::*;
/// use ruststream::Seeker;
/// use ruststream_sea_file::{FileContext, FilePosition, SeekHandle};
/// # #[derive(serde::Deserialize)]
/// # struct Job { id: u64 }
///
/// struct Replayer;
///
/// impl Handle<Job, (), (), FileContext> for Replayer {
/// async fn handle(
/// &self,
/// job: &Job,
/// _outs: &(),
/// ctx: &mut Context<'_, FileContext>,
/// ) -> Result<(), HandlerOutcome> {
/// if job.id == 0 && ctx.context(SeekHandle).seek(FilePosition::end()).await.is_err() {
/// return Err(HandlerOutcome::retry());
/// }
/// Ok(())
/// }
/// }
/// ```
/// The file transport's subscription-scoped batch context: the subscription's own seeker, shared
/// by every delivery of the batch.
///
/// The runtime builds one per dispatched batch from the batch's first delivery, and a batch body
/// reads it by key - [`SeekHandle`]. Per-delivery data (a [`Position`]) has no place here: a
/// batch spans many deliveries, so the position a body reacts to rides the elements themselves,
/// and keeping this a separate type from [`FileContext`] is what rejects a batch body asking for
/// per-delivery fields at compile time.
///
/// # Examples
///
/// ```
/// use ruststream::prelude::*;
/// use ruststream::Seeker;
/// use ruststream_sea_file::{FileBatchContext, FilePosition, SeekHandle};
/// # #[derive(serde::Deserialize)]
/// # struct Job { id: u64 }
///
/// struct Replayer;
///
/// impl Handle<[Job], (), (), FileBatchContext> for Replayer {
/// async fn handle(
/// &self,
/// batch: &[Job],
/// _outs: &(),
/// ctx: &mut Context<'_, FileBatchContext>,
/// ) -> Result<(), Vec<HandlerOutcome>> {
/// if batch.iter().any(|job| job.id == 0)
/// && ctx.context(SeekHandle).seek(FilePosition::end()).await.is_err()
/// {
/// return Err(batch.iter().map(|_| HandlerOutcome::retry()).collect());
/// }
/// Ok(())
/// }
/// }
/// ```
/// The key reading this delivery's [`FilePosition`] out of [`FileContext`].
///
/// The value is the pinned form: seeking back to it redelivers exactly this message.
///
/// # Examples
///
/// ```
/// use ruststream_sea_file::file::prelude::*;
/// # #[derive(serde::Deserialize)]
/// # struct Job { id: u64 }
///
/// #[subscriber(FileStream::new("jobs"))]
/// async fn audit(job: &Job, Ctx(at): Ctx<Position>) -> HandlerOutcome {
/// println!("job {} sits at {at:?}", job.id);
/// HandlerOutcome::ack()
/// }
/// ```
;
/// The key reading the subscription's [`FileSeeker`] out of [`FileContext`] or
/// [`FileBatchContext`]: the reposition handle, resolved once when the subscription opens and
/// carried by every delivery.
///
/// # Examples
///
/// ```
/// use ruststream_sea_file::file::prelude::*;
/// # #[derive(serde::Deserialize)]
/// # struct Job { id: u64, poisoned: bool }
///
/// /// Skips to the live tail when the producer marks a poisoned region.
/// #[subscriber(FileStream::new("jobs"))]
/// async fn work(job: &Job, Ctx(seeker): Ctx<SeekHandle>) -> HandlerOutcome {
/// if job.poisoned && seeker.seek(FilePosition::end()).await.is_err() {
/// return HandlerOutcome::retry();
/// }
/// HandlerOutcome::ack()
/// }
/// ```
;