pub struct SseMessage<W: Write>(/* private fields */);Expand description
An SSE message.
Each message consists of any number of fields followed by a message terminating
sequence. The member functions allow “appending” a field to the message any number of
times, and when the SseMessage goes out of scope, the message is flushed and
terminated.
Implementations§
Source§impl<W: Write> SseMessage<W>
impl<W: Write> SseMessage<W>
Sourcepub fn data(&mut self) -> Result<SseField<&mut W>>
pub fn data(&mut self) -> Result<SseField<&mut W>>
Append a data field.
This is the data payload passed into the browser event listener callback when the message is terminated. It can be raw text, JSON, or any other format. If a message contains multiple data fields, the browser concatenates their values until the end of the message.
This field is the only “required” one, in that a message with an empty data field won’t trigger any event listener in the browser.
Sourcepub fn event(&mut self) -> Result<SseField<&mut W>>
pub fn event(&mut self) -> Result<SseField<&mut W>>
Append an event name field.
This optional field tags the current message with an event name, which causes the browser to trigger an event listener specifically for that event.
Sourcepub fn id(&mut self) -> Result<SseField<&mut W>>
pub fn id(&mut self) -> Result<SseField<&mut W>>
Append an event ID field.
This optional field sets the “last event ID” of the current event stream.