pub struct Event { /* private fields */ }
Expand description
Server-sent event
Implementations
sourceimpl Event
impl Event
sourcepub fn data<T>(self, data: T) -> Event where
T: Into<String>,
pub fn data<T>(self, data: T) -> Event where
T: Into<String>,
Set the event’s data data field(s) (data:<content>
)
Newlines in data
will automatically be broken across data:
fields.
This corresponds to MessageEvent
’s data field.
Panics
Panics if data
contains any carriage returns, as they cannot be transmitted over SSE.
sourcepub fn json_data<T>(self, data: T) -> Result<Event> where
T: Serialize,
This is supported on crate feature json
only.
pub fn json_data<T>(self, data: T) -> Result<Event> where
T: Serialize,
json
only.Set the event’s data field to a value serialized as unformatted JSON (data:<content>
).
This corresponds to MessageEvent
’s data field.
sourcepub fn comment<T>(self, comment: T) -> Event where
T: Into<String>,
pub fn comment<T>(self, comment: T) -> Event where
T: Into<String>,
Set the event’s comment field (:<comment-text>
).
This field will be ignored by most SSE clients.
Panics
Panics if comment
contains any newlines or carriage returns, as they are not allowed in
comments.
sourcepub fn event<T>(self, event: T) -> Event where
T: Into<String>,
pub fn event<T>(self, event: T) -> Event where
T: Into<String>,
Set the event’s name field (event:<event-name>
).
This corresponds to the type
parameter given when calling addEventListener
on an
EventSource
. For example, .event("update")
should correspond to
.addEventListener("update", ...)
. If no event type is given, browsers will fire a
message
event instead.
Panics
Panics if event
contains any newlines or carriage returns.
sourcepub fn retry(self, duration: Duration) -> Event
pub fn retry(self, duration: Duration) -> Event
Set the event’s retry timeout field (retry:<timeout>
).
This sets how long clients will wait before reconnecting if they are disconnected from the SSE endpoint. Note that this is just a hint: clients are free to wait for longer if they wish, such as if they implement exponential backoff.
sourcepub fn id<T>(self, id: T) -> Event where
T: Into<String>,
pub fn id<T>(self, id: T) -> Event where
T: Into<String>,
Set the event’s identifier field (id:<identifier>
).
This corresponds to MessageEvent
’s lastEventId
field. If no ID is in the event itself,
the browser will set that field to the last known message ID, starting with the empty
string.
Panics
Panics if id
contains any newlines, carriage returns or null characters.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Event
impl Send for Event
impl Sync for Event
impl Unpin for Event
impl UnwindSafe for Event
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> PolicyExt for T where
T: ?Sized,
impl<T> PolicyExt for T where
T: ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more