pub struct SseEvent {
pub data: String,
pub event: Option<String>,
pub id: Option<String>,
pub retry: Option<u64>,
}Expand description
A single Server-Sent Event, serializable to the WHATWG text/event-stream wire format.
Field ordering in the wire output follows the WHATWG spec recommendation:
event:, id:, retry:, then one or more data: lines, terminated by a blank line.
§Example
let event = SseEvent::data("hello")
.event("token")
.id("42")
.retry(3000);
// Wire: "event: token\nid: 42\nretry: 3000\ndata: hello\n\n"Fields§
§data: StringThe event payload. Multi-line strings produce repeated data: lines.
event: Option<String>Optional named event type (event: field).
id: Option<String>Optional last-event ID (id: field).
retry: Option<u64>Optional client reconnection delay in milliseconds (retry: field).
Implementations§
Source§impl SseEvent
impl SseEvent
Sourcepub fn data(data: impl Into<String>) -> Self
pub fn data(data: impl Into<String>) -> Self
Create an event with the given data string.
This is the primary constructor; chain .event(), .id(), .retry() for additional fields.
Sourcepub fn event(self, event: impl Into<String>) -> Self
pub fn event(self, event: impl Into<String>) -> Self
Set the named event type.
event is a single-line SSE field. Any \n, \r, or \0 characters in the value
are stripped to prevent SSE field injection (and, for id, last-event-id resets).
data may contain newlines (rendered as multiple data: lines per the WHATWG
spec), so it is not stripped.
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 UnsafeUnpin 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
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: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<E> IntoActionError for Ewhere
E: Display,
impl<E> IntoActionError for Ewhere
E: Display,
Source§fn into_action_error(self) -> ActionError
fn into_action_error(self) -> ActionError
ActionError.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> OrderedContainer<T> for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.