axum::response::sse

Struct Event

Source
pub struct Event { /* private fields */ }
Available on crate feature tokio only.
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,

Available on crate feature json only.

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§

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

🔬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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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