pub struct SseEvent {
pub data: String,
pub event: Option<String>,
pub id: Option<String>,
pub retry: Option<u64>,
/* private fields */
}Expand description
A Server-Sent Event
SSE events follow the format specified in the W3C Server-Sent Events specification. Each event can have:
data: The event data (required)event: The event type/name (optional)id: The event ID for reconnection (optional)retry: Reconnection time in milliseconds (optional)comment: A comment line (optional, not visible to most clients)
Fields§
§data: StringThe event data
event: Option<String>The event type/name
id: Option<String>The event ID
retry: Option<u64>Reconnection time in milliseconds
Implementations§
Source§impl SseEvent
impl SseEvent
Sourcepub fn comment(text: impl Into<String>) -> SseEvent
pub fn comment(text: impl Into<String>) -> SseEvent
Create an SSE comment (keep-alive)
Comments are lines starting with : and are typically used for keep-alive.
Sourcepub fn json_data<T>(data: &T) -> Result<SseEvent, Error>where
T: Serialize,
pub fn json_data<T>(data: &T) -> Result<SseEvent, Error>where
T: Serialize,
Set JSON data (serializes the value)
Sourcepub fn to_sse_string(&self) -> String
pub fn to_sse_string(&self) -> String
Format the event as an SSE message
The format follows the SSE specification:
- Lines starting with “event:” specify the event type
- Lines starting with “id:” specify the event ID
- Lines starting with “retry:” specify the reconnection time
- Lines starting with “data:” contain the event data
- Lines starting with “:” are comments
- Events are terminated with a blank line
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SseEvent
impl RefUnwindSafe for SseEvent
impl Send for SseEvent
impl Sync for SseEvent
impl Unpin for SseEvent
impl UnwindSafe for SseEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more