gloo_net/eventsource/
mod.rs

1//! Wrapper around the `EventSource` API
2//!
3//! This API is provided in the following flavors:
4//! - [Futures API][futures]
5
6pub mod futures;
7
8use std::fmt;
9
10/// The state of the EventSource.
11///
12/// See [`EventSource.readyState` on MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/readyState)
13/// to learn more.
14#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
15pub enum State {
16    /// The connection has not yet been established.
17    Connecting,
18    /// The EventSource connection is established and communication is possible.
19    Open,
20    /// The connection has been closed or could not be opened.
21    Closed,
22}
23
24/// Error returned by the EventSource
25#[derive(Clone, Debug, Eq, PartialEq)]
26#[non_exhaustive]
27#[allow(missing_copy_implementations)]
28pub enum EventSourceError {
29    /// The `error` event
30    ConnectionError,
31}
32
33impl fmt::Display for EventSourceError {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        match self {
36            EventSourceError::ConnectionError => write!(f, "EventSource connection failed"),
37        }
38    }
39}