Skip to main content

frame

Function frame 

Source
pub fn frame(payload: &str) -> String
Expand description

Wraps an arbitrary payload in an SSE data: block.

A payload containing line breaks becomes one data: line per line, which is what the SSE decoder rejoins with \n; a payload with none becomes a single line. Serialized JSON is always single-line — serde_json escapes control characters — so this only matters for callers that frame something else, but getting it wrong would silently truncate an event at the first newline.

assert_eq!(frame("one\ntwo"), "data: one\ndata: two\n\n");