pub enum Replay<'a, T> {
UpToDate {
last: EventId,
},
Buffered {
events: &'a [StreamEvent<T>],
last: EventId,
},
Gap {
requested: EventId,
evicted_through: EventId,
last: EventId,
},
Unknown {
requested: EventId,
last: EventId,
},
}Expand description
What a client asking to resume actually gets.
Four arms, and the distinction that matters is between the first two and the
last two. UpToDate and Buffered are success: nothing was lost. Gap and
Unknown are refusals, and a caller that collapses them into an empty list
has just reported a lost event as a success — which is the specific failure
this enum is shaped to make awkward.
Variants§
UpToDate
The client is already current. There is genuinely nothing to send.
Buffered
Everything after the client’s watermark is still held. Send all of it.
Fields
events: &'a [StreamEvent<T>]The events, oldest first, contiguous from the watermark.
Gap
The client is behind the point where events started being dropped, so a resume would silently omit what it missed. The client must be told, and must re-issue whatever it has not seen.
Fields
Unknown
The client quoted an id the stream never issued.
Separate from Gap on purpose. A gap means the client is
behind and something was lost; this means the client’s id is ahead of
anything that exists, which is a client that is out of step with the
server — a different fault with a different fix, and one that a
“resume from the beginning” fallback would paper over.
Implementations§
Source§impl<T> Replay<'_, T>
impl<T> Replay<'_, T>
Sourcepub const fn is_complete(&self) -> bool
pub const fn is_complete(&self) -> bool
Whether the client’s request can be honoured without losing an event.
The one question an adapter has to answer before writing a response
body, and it is false for exactly the two arms where a naive
implementation would send a partial stream and call it a success.
Sourcepub const fn events(&self) -> &[StreamEvent<T>]
pub const fn events(&self) -> &[StreamEvent<T>]
The events to write, if any.
Empty for both refusals, which is why it is not the thing to branch on:
use is_complete for that. Provided for the write
loop, which has nothing to do after being told about a gap.