Struct axum::response::sse::Event

source ·
pub struct Event { /* private fields */ }
Expand description

Server-sent event

Implementations§

source§

impl Event

source

pub fn data<T>(self, data: T) -> Event
where T: AsRef<str>,

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.

Note that events with an empty data field will be ignored by the browser.

§Panics
  • Panics if data contains any carriage returns, as they cannot be transmitted over SSE.
  • Panics if data or json_data have already been called.
source

pub fn json_data<T>(self, data: T) -> Result<Event, Error>
where T: Serialize,

Set the event’s data field to a value serialized as unformatted JSON (data: <content>).

This corresponds to MessageEvent’s data field.

§Panics

Panics if data or json_data have already been called.

source

pub fn comment<T>(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 comment contains any newlines or carriage returns, as they are not allowed in comments.

source

pub fn event<T>(self, event: T) -> Event
where T: AsRef<str>,

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.
  • Panics if this function has already been called on this event.
source

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.

§Panics

Panics if this function has already been called on this event.

source

pub fn id<T>(self, id: T) -> Event
where T: AsRef<str>,

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.
  • Panics if this function has already been called on this event.

Trait Implementations§

source§

impl Clone for Event

source§

fn clone(&self) -> Event

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Event

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Event

source§

fn default() -> Event

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more