pub struct SseEvent {
pub id: Option<String>,
pub event: Option<String>,
pub data: String,
pub retry: Option<u64>,
/* private fields */
}Expand description
A single Server-Sent Event.
Fields are formatted per the WHATWG SSE spec. Multi-line data strings
are split on \n and emitted as separate data: lines, which the client
concatenates back into a single message.
Construct comment-only frames (used for keep-alive heartbeats) with
SseEvent::comment. Comments are written as :<text>\n\n and ignored
by clients.
Fields§
§id: Option<String>Optional event ID, sent as id: <value>.
event: Option<String>Optional event name, sent as event: <value>.
data: StringThe event payload, sent as one or more data: <line> lines.
retry: Option<u64>Optional reconnection time hint in milliseconds, sent as retry: <ms>.
Implementations§
Source§impl SseEvent
impl SseEvent
Sourcepub fn comment(text: impl Into<String>) -> Self
pub fn comment(text: impl Into<String>) -> Self
Create a comment-only frame (e.g. :keepalive).
Comments are ignored by SSE clients per the spec but keep the connection alive through proxies that close idle TCP connections.
Sourcepub fn with_event(self, event: impl Into<String>) -> Self
pub fn with_event(self, event: impl Into<String>) -> Self
Set the event name.
Sourcepub fn with_retry(self, ms: u64) -> Self
pub fn with_retry(self, ms: u64) -> Self
Set the reconnection time hint in milliseconds.