pub struct Sse { /* private fields */ }Expand description
Builder for a buffered Server-Sent Events response.
Call Sse::into_response to obtain a Response with:
200 OKContent-Type: text/event-streamCache-Control: no-cacheX-Accel-Buffering: no(disables nginx proxy buffering)
§Example
use rust_web_server::sse::Sse;
let response = Sse::new()
.event("open", "")
.data(r#"{"msg":"hello"}"#)
.retry(5000)
.into_response();Implementations§
Source§impl Sse
impl Sse
Sourcepub fn event(self, event_type: &str, data: &str) -> Self
pub fn event(self, event_type: &str, data: &str) -> Self
Append a named event with data.
event_type becomes the event: field; data becomes the data: field.
Sourcepub fn data(self, data: &str) -> Self
pub fn data(self, data: &str) -> Self
Append a data-only event (no event: type field; clients receive it as
"message").
Sourcepub fn push(self, event: SseEvent) -> Self
pub fn push(self, event: SseEvent) -> Self
Append a fully configured SseEvent (id, type, retry, data).
Sourcepub fn retry(self, ms: u32) -> Self
pub fn retry(self, ms: u32) -> Self
Append a retry: directive that tells the client how many milliseconds
to wait before reconnecting after the connection is lost.
Sourcepub fn comment(self, text: &str) -> Self
pub fn comment(self, text: &str) -> Self
Append an SSE comment line (starts with :). Used as a keep-alive ping
or annotation; browsers ignore comment content.
Sourcepub fn into_response(self) -> Response
pub fn into_response(self) -> Response
Finalise the builder and return a Response with the correct SSE
headers and the accumulated event body.
Auto Trait Implementations§
impl Freeze for Sse
impl RefUnwindSafe for Sse
impl Send for Sse
impl Sync for Sse
impl Unpin for Sse
impl UnsafeUnpin for Sse
impl UnwindSafe for Sse
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