pub struct SseEvent { /* private fields */ }Expand description
One frame in a Server-Sent Events stream. A frame may carry data
(the common case), a comment (heartbeats and debug pings), and the
optional event / id / retry fields. The wire encoding is handled
by SseEvent::to_bytes — embedded newlines in data become multiple
data: lines, the way the spec requires.
SseEvent::data("hello").event("greeting").id("42")
SseEvent::data("line1\nline2") // becomes two `data: ...` lines
SseEvent::comment("keep-alive")Implementations§
Source§impl SseEvent
impl SseEvent
Sourcepub fn data(data: impl Into<String>) -> SseEvent
pub fn data(data: impl Into<String>) -> SseEvent
New event with a data: field. The most common entry point.
Sourcepub fn comment(text: impl Into<String>) -> SseEvent
pub fn comment(text: impl Into<String>) -> SseEvent
New event with just a comment line (: ...\n\n). Comments are
ignored by EventSource clients but keep the connection alive
through intermediaries — useful as a heartbeat when the stream is
idle for long stretches.
Sourcepub fn event(self, name: impl Into<String>) -> SseEvent
pub fn event(self, name: impl Into<String>) -> SseEvent
Set the event-type name (the event: field). Clients can route on
this with EventSource.addEventListener(name, …). Embedded newlines
are replaced with spaces (the spec doesn’t allow newlines in event
names).
Sourcepub fn id(self, id: impl Into<String>) -> SseEvent
pub fn id(self, id: impl Into<String>) -> SseEvent
Set the id: field. The browser will replay it on reconnect via
the Last-Event-ID request header — use it to support resumable
streams.