Struct Event
struct Event { ... }
Server-sent event
Implementations
impl Event
fn data<T>(self: Self, data: T) -> Event where T: AsRef<str>Set the event's data data field(s) (
data: <content>)Newlines in
datawill automatically be broken acrossdata:fields.This corresponds to
MessageEvent's data field.Note that events with an empty data field will be ignored by the browser.
Panics
- Panics if
datacontains any carriage returns, as they cannot be transmitted over SSE. - Panics if
dataorjson_datahave already been called.
- Panics if
fn json_data<T>(self: Self, data: T) -> Result<Event, axum_core::Error> where T: serde::SerializeSet the event's data field to a value serialized as unformatted JSON (
data: <content>).This corresponds to
MessageEvent's data field.Panics
Panics if
dataorjson_datahave already been called.fn comment<T>(self: Self, comment: T) -> Event where T: AsRef<str>Set the event's comment field (
:<comment-text>).This field will be ignored by most SSE clients.
Unlike other functions, this function can be called multiple times to add many comments.
Panics
Panics if
commentcontains any newlines or carriage returns, as they are not allowed in comments.fn event<T>(self: Self, event: T) -> Event where T: AsRef<str>Set the event's name field (
event:<event-name>).This corresponds to the
typeparameter given when callingaddEventListeneron anEventSource. For example,.event("update")should correspond to.addEventListener("update", ...). If no event type is given, browsers will fire amessageevent instead.Panics
- Panics if
eventcontains any newlines or carriage returns. - Panics if this function has already been called on this event.
- Panics if
fn retry(self: Self, duration: Duration) -> EventSet 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.
Panics
Panics if this function has already been called on this event.
fn id<T>(self: Self, id: T) -> Event where T: AsRef<str>Set the event's identifier field (
id:<identifier>).This corresponds to
MessageEvent'slastEventIdfield. 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
idcontains any newlines, carriage returns or null characters. - Panics if this function has already been called on this event.
- Panics if
impl Clone for Event
fn clone(self: &Self) -> Event
impl Debug for Event
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for Event
fn default() -> Event
impl Freeze for Event
impl RefUnwindSafe for Event
impl Send for Event
impl Sync for Event
impl Unpin for Event
impl UnwindSafe for Event
impl<T> Any for Event
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Event
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Event
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Event
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Event
fn from(t: T) -> TReturns the argument unchanged.
impl<T> FromRef for Event
fn from_ref(input: &T) -> T
impl<T> Instrument for Event
impl<T> Same for Event
impl<T> ToOwned for Event
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> WithSubscriber for Event
impl<T, U> Into for Event
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Event
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Event
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<V, T> VZip for Event
fn vzip(self: Self) -> V