pub struct SseEvent { /* private fields */ }Expand description
A Server-Sent Event.
Events consist of one or more fields:
data: The message payload (required, can contain newlines)event: The event type (optional, defaults to “message”)id: An identifier for the event (optional, used for resumption)retry: Reconnection time in milliseconds (optional)comment: A comment (not delivered to the event listener)
§Example
ⓘ
use fastapi_core::sse::SseEvent;
// Simple message
let event = SseEvent::message("Hello, World!");
// Event with type and ID
let event = SseEvent::new("user joined")
.event_type("join")
.id("123");
// JSON data
let event = SseEvent::new(r#"{"user":"alice","action":"login"}"#)
.event_type("user_event");
// Keep-alive comment
let event = SseEvent::comment("keep-alive");Implementations§
Source§impl SseEvent
impl SseEvent
Sourcepub fn new(data: impl Into<String>) -> Self
pub fn new(data: impl Into<String>) -> Self
Create a new SSE event with the given data.
The data can contain newlines - each line will be prefixed with data: .
Sourcepub fn message(data: impl Into<String>) -> Self
pub fn message(data: impl Into<String>) -> Self
Create a simple message event.
Equivalent to SseEvent::new(data).
Sourcepub fn event_type(self, event_type: impl Into<String>) -> Self
pub fn event_type(self, event_type: impl Into<String>) -> Self
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).