EventSource

Trait EventSource 

Source
pub trait EventSource {
    // Required method
    fn events(
        self,
    ) -> impl Future<Output = Result<Pin<Box<impl Stream<Item = Result<Event, EventError>>>>, EventSourceError>> + Send;
}
Expand description

A trait for consuming a Response as a Stream of Server-Sent Events (SSE).

Required Methods§

Source

fn events( self, ) -> impl Future<Output = Result<Pin<Box<impl Stream<Item = Result<Event, EventError>>>>, EventSourceError>> + Send

Converts the Response into a stream of Server-Sent Events. Returns it as a faillable Stream of Events.

§Errors

Returns an EventSourceError if:

  • The response status is not 200 OK
  • The Content-Type header is missing or not text/event-stream

The stream yields an EventError when error occure on event reading.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EventSource for Response

Source§

async fn events( self, ) -> Result<Pin<Box<impl Stream<Item = Result<Event, EventError>>>>, EventSourceError>

Implementors§