Struct Event

#[must_use]
pub struct Event { /* private fields */ }

Server-sent event

Implementations

impl Event

const DEFAULT_KEEP_ALIVE: Self = _;

Default keep-alive event

fn into_data_writer(self) -> EventDataWriter

Use this Event as a EventDataWriter to write custom data.

Turn it into an Event again using EventDataWriter::into_event.

fn data<T>(self, data: T) -> Self
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 any data has already been written before.

fn json_data<T>(self, data: T) -> Result<Self, 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 any data has already been written before.

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.

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

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

impl Clone for Event

fn clone(&self) -> Self

impl Debug for Event

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

impl Default for Event

fn default() -> Self

Auto Trait Implementations

impl !Freeze for Event

impl RefUnwindSafe for Event

impl Send for Event

impl Sync for Event

impl Unpin for Event

impl UnsafeUnpin for Event

impl UnwindSafe for Event

Blanket Implementations

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Event where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Event where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

impl<T> From<T> for Event

fn from(t: T) -> T

Returns the argument unchanged.

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

fn from_ref(input: &T) -> T

impl<T> Instrument for Event

impl<T> Read<Exclusive, BecauseExclusive> for Event where T: ?Sized,

impl<T> Same for Event

type Output = T;

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> WithSubscriber for Event

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

fn into(self) -> U

Calls U::from(self).

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

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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

impl<V, T> VZip<V> for Event where V: MultiLane<T>,

fn vzip(self) -> V