Skip to main content

Event

Struct Event 

Source
pub struct Event { /* private fields */ }
Expand description

Events are a concrete implementation of the Eventable trait.

Implementations§

Source§

impl Event

Source

pub fn data(&self) -> Option<&str>

Borrows the data for this event

Source

pub fn data_mut(&mut self) -> Option<&mut Cow<'static, str>>

Mutably borrow the data for this event

Source

pub fn set_data(&mut self, data: impl Into<Cow<'static, str>>) -> &mut Self

Sets the data for this event, returning &mut Self for chaining

Source

pub fn with_data(self, data: impl Into<Cow<'static, str>>) -> Self

Owned chainable setter for the data for this event, returning Self

Source

pub fn comment(&self) -> Option<&str>

Borrows a comment for this event

Source

pub fn comment_mut(&mut self) -> Option<&mut Cow<'static, str>>

Mutably borrow a comment for this event

Source

pub fn set_comment( &mut self, comment: impl Into<Cow<'static, str>>, ) -> &mut Self

Sets a comment for this event, returning &mut Self for chaining

Source

pub fn with_comment(self, comment: impl Into<Cow<'static, str>>) -> Self

Owned chainable setter for a comment for this event, returning Self

Source

pub fn event_type(&self) -> Option<&str>

Borrows the type for this event

Source

pub fn type_mut(&mut self) -> Option<&mut Cow<'static, str>>

Mutably borrow the type for this event

Source

pub fn set_type( &mut self, event_type: impl Into<Cow<'static, str>>, ) -> &mut Self

Sets the type for this event, returning &mut Self for chaining

Source

pub fn with_type(self, event_type: impl Into<Cow<'static, str>>) -> Self

Owned chainable setter for the type for this event, returning Self

Source

pub fn id(&self) -> Option<&str>

Borrows the id for this event

Source

pub fn id_mut(&mut self) -> Option<&mut Cow<'static, str>>

Mutably borrow the id for this event

Source

pub fn set_id(&mut self, id: impl Into<Cow<'static, str>>) -> &mut Self

Sets the id for this event, returning &mut Self for chaining

Source

pub fn with_id(self, id: impl Into<Cow<'static, str>>) -> Self

Owned chainable setter for the id for this event, returning Self

Source

pub fn retry(&self) -> Option<Duration>

Returns a copy of reconnection time for this stream

Source

pub fn retry_mut(&mut self) -> Option<&mut Duration>

Mutably borrow reconnection time for this stream

Source

pub fn set_retry(&mut self, retry: Duration) -> &mut Self

Sets reconnection time for this stream, returning &mut Self for chaining

Source

pub fn with_retry(self, retry: Duration) -> Self

Owned chainable setter for reconnection time for this stream, returning Self

Source§

impl Event

Source

pub fn new(data: impl Into<Cow<'static, str>>) -> Self

builds a new Event

by default, this event has no event type. to set an event type, use Event::with_type or Event::set_type

Source

pub fn new_comment(comment: impl Into<Cow<'static, str>>) -> Self

builds a new comment-only Event, with no data

Clients ignore comments and dispatch no event for this message. Sending one periodically keeps an otherwise idle event stream from being closed by intermediaries.

let event = trillium_sse::Event::new_comment("heartbeat");
assert_eq!(event.comment(), Some("heartbeat"));
assert_eq!(event.data(), None);

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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
Source§

impl Eq for Event

Source§

impl Eventable for Event

Source§

fn data(&self) -> Option<&str>

return the data for this event, if any Read more
Source§

fn comment(&self) -> Option<&str>

return a comment to send alongside this event, optionally Read more
Source§

fn event_type(&self) -> Option<&str>

return the event type, optionally
Source§

fn id(&self) -> Option<&str>

return a unique event id, optionally
Source§

fn retry(&self) -> Option<Duration>

return a reconnection time to request of the client, optionally Read more
Source§

impl From<&'static str> for Event

Source§

fn from(s: &'static str) -> Self

Converts to this type from the input type.
Source§

impl From<Cow<'static, str>> for Event

Source§

fn from(data: Cow<'static, str>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Event

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Event

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§

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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.