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
//! Peek reader decorator (#146).
//!
//! [`PeekReader`] looks ahead at the next logical item without corrupting
//! ordering or advancing durable progress incorrectly: it buffers at most one
//! outcome from its delegate, so repeated peeking never calls the delegate
//! again, and the following [`crate::ItemReader::read`] call consumes exactly
//! that buffered outcome exactly once.
use crate::;
/// The outcome of [`PeekReader::peek`], borrowing the buffered item rather
/// than consuming it.
/// A reader decorator that can look ahead at the next logical item.
///
/// # Contract
///
/// - **Input/output**: `I`, same as the delegate `R`.
/// - **State/checkpoint**: the buffered lookahead is in-memory only. It adds
/// no durable state and advances no checkpoint by itself: the delegate's
/// [`crate::ItemReader::read`] is called at most once before its outcome is
/// returned to the caller through a real `read` call, exactly like an
/// undecorated reader, so the chunk runtime's own read-ordinal/checkpoint
/// bookkeeping observes exactly the same call/outcome pairing it would
/// without peeking. If the delegate is itself paired with a
/// [`crate::ItemStream`] for durable position, that pairing is unaffected:
/// a restart resumes the delegate from its own last committed position,
/// and any not-yet-`read` peeked value is simply re-derived by the first
/// `peek`/`read` call of the new attempt (see restartability below).
/// - **Restartability**: exactly the delegate's; this wrapper never persists
/// the buffered lookahead across an attempt boundary, so an attempt that
/// ends before consuming a peeked value loses nothing durable -- it was
/// never reported as read to the framework.
/// - **Ordering**: preserves the delegate's order; `peek` never reorders or
/// skips.
/// - **Thread safety**: used exclusively (`&mut self`) like every reader.
/// - **Bounded resource**: buffers at most one outcome.
/// - **Cancellation**: a [`PeekOutcome::Stopped`]/[`ReadOutcome::Stopped`]
/// observed while peeking is cached and returned by the next `read` too,
/// consistent with the delegate's own stable stop behavior.
/// - **Close**: nothing to close.
/// - **Malformed input**: propagates the delegate's [`ReaderError`]
/// unchanged; an error is never cached, so the next `peek`/`read` retries
/// the delegate.
/// - **Support tier**: first-party.
/// - **Evidence**: `crates/oxide-batch-test/tests/item_components_decorators.rs`.