[][src]Struct hyper_usse::Event

pub struct Event {
    pub id: Option<Cow<'static, str>>,
    pub event: Option<Cow<'static, str>>,
    pub data: Cow<'static, str>,
}

A server sent event.

The fields id, event and data set the id, event and data parameters for the event respectively. id and event are optional. To convert it to an SSE string, use the to_sse function.

Examples

let event = hyper_usse::Event::new("some text\nmore text").set_id("1").set_event("send_text");
assert_eq!(event.to_sse(), "id: 1
event: send_text
data: some text
data: more text\n\n");

Fields

id: Option<Cow<'static, str>>event: Option<Cow<'static, str>>data: Cow<'static, str>

Methods

impl Event[src]

pub fn new<T: Into<Cow<'static, str>>>(data: T) -> Self[src]

Creates a new Event from data.

pub fn set_id<T: Into<Cow<'static, str>>>(self, id: T) -> Self[src]

Sets the id of the event. As it returns self, it is useful for creating an event inline.

pub fn set_event<T: Into<Cow<'static, str>>>(self, event: T) -> Self[src]

Sets the event type of the event. Like set_id, it returns self and so can easily be chained.

pub fn to_sse(&self) -> String[src]

Converts the Event to an SSE string.

Trait Implementations

impl Debug for Event[src]

impl Default for Event[src]

Auto Trait Implementations

impl RefUnwindSafe for Event

impl Send for Event

impl Sync for Event

impl Unpin for Event

impl UnwindSafe for Event

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.