SseMessage

Struct SseMessage 

Source
pub struct SseMessage<W: Write>(/* private fields */);
Expand description

An SSE message.

Each message consists of any number of fields followed by a message terminating sequence. The member functions allow “appending” a field to the message any number of times, and when the SseMessage goes out of scope, the message is flushed and terminated.

Implementations§

Source§

impl<W: Write> SseMessage<W>

Source

pub fn new(stream: W) -> Self

Create a new SseMessage to write into the given stream.

Source

pub fn data(&mut self) -> Result<SseField<&mut W>>

Append a data field.

This is the data payload passed into the browser event listener callback when the message is terminated. It can be raw text, JSON, or any other format. If a message contains multiple data fields, the browser concatenates their values until the end of the message.

This field is the only “required” one, in that a message with an empty data field won’t trigger any event listener in the browser.

Source

pub fn event(&mut self) -> Result<SseField<&mut W>>

Append an event name field.

This optional field tags the current message with an event name, which causes the browser to trigger an event listener specifically for that event.

Source

pub fn id(&mut self) -> Result<SseField<&mut W>>

Append an event ID field.

This optional field sets the “last event ID” of the current event stream.

Source

pub fn retry(&mut self) -> Result<SseField<&mut W>>

Append a retry field.

This optional field must be an integer and sets the reconnection time of the current event stream, which is the millisecond delay used when the browser attempts to reestablish a connection to the stream.

Source

pub fn finish(&mut self) -> Result<()>

Terminate the current message and begin a new one.

Trait Implementations§

Source§

impl<W: Write> Drop for SseMessage<W>

Writes the message terminating sequence and flushes on drop.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<W> Freeze for SseMessage<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for SseMessage<W>
where W: RefUnwindSafe,

§

impl<W> Send for SseMessage<W>
where W: Send,

§

impl<W> Sync for SseMessage<W>
where W: Sync,

§

impl<W> Unpin for SseMessage<W>
where W: Unpin,

§

impl<W> UnwindSafe for SseMessage<W>
where W: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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