Skip to main content

Eventable

Trait Eventable 

Source
pub trait Eventable:
    Unpin
    + Send
    + Sync
    + 'static {
    // Required method
    fn data(&self) -> Option<&str>;

    // Provided methods
    fn comment(&self) -> Option<&str> { ... }
    fn event_type(&self) -> Option<&str> { ... }
    fn id(&self) -> Option<&str> { ... }
    fn retry(&self) -> Option<Duration> { ... }
}
Expand description

A trait that allows any Unpin + Send + Sync type to act as an event.

For a concrete implementation of this trait, you can use Event, but it is also implemented for String and [&'static str].

Required Methods§

Source

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

return the data for this event, if any

Returning None yields a message with no data: field. Clients dispatch no event for such a message, so it is only useful in combination with comment.

Provided Methods§

Source

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

return a comment to send alongside this event, optionally

Comments are ignored by clients. They are chiefly used as a heartbeat, sent periodically so that an idle event stream is still producing traffic.

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

Sent as a retry: field in milliseconds, truncated. Clients that reconnect on their own — such as the browser EventSource — wait this long before doing so. Whether and how it is honored is entirely up to the client.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Eventable for &'static str

Source§

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

Source§

impl Eventable for String

Source§

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

Implementors§