expression
SSE: model replay after Last-Event-ID
A reconnecting EventSource can report its last event ID. This model uses a bounded numeric event log and replays IDs after the known cursor. A real service must authenticate the subscriber, validate cursor ownership and handle missing history explicitly; SSE IDs are generally strings, not necessarily integers. Standalone synthetic example. Expected stdout (not executed): 11: packed 12: shipped Common mistake: Assuming an arbitrary cursor belongs to the current user or that the history has no gaps.
Formal Syntax & Structure
rust syntaxrust
events.iter().filter(|(id, _)| *id > last_id)Working Example
Example Snippetrust
use axum::{Router, body::{Body, to_bytes}, http::{Request, StatusCode}, response::{IntoResponse, sse::{Event, Sse}}, extract::ws::{Message, WebSocketUpgrade, WebSocket}};use std::convert::Infallible;use futures_util::stream;use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() { let log = [(10_u64, "created"), (11, "packed"), (12, "shipped")]; let last_id = "10".parse::<u64>().unwrap(); assert!(log.iter().any(|(id, _)| *id == last_id)); for (id, value) in log.iter().filter(|(id, _)| *id > last_id) { println!("{id}: {value}"); }}