async_sse/lib.rs
1//! Async Server Sent Event parser and encoder.
2//!
3//! # Example
4//!
5//! ```
6//! use async_sse::{decode, encode, Event};
7//! use async_std::prelude::*;
8//! use async_std::io::BufReader;
9//! use async_std::task;
10//!
11//! #[async_std::main]
12//! async fn main() -> http_types::Result<()> {
13//! // Create an encoder + sender pair and send a message.
14//! let (sender, encoder) = encode();
15//! task::spawn(async move {
16//! sender.send("cat", "chashu", None).await;
17//! });
18//!
19//! // Decode messages using a decoder.
20//! let mut reader = decode(BufReader::new(encoder));
21//! let event = reader.next().await.unwrap()?;
22//! // Match and handle the event
23//!
24//! # let _ = event;
25//! Ok(())
26//! }
27//! ```
28//!
29//! # References
30//!
31//! - [SSE Spec](https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-last-event-id)
32//! - [EventSource web platform tests](https://github.com/web-platform-tests/wpt/tree/master/eventsource)
33
34#![deny(missing_debug_implementations, nonstandard_style)]
35#![warn(missing_docs, rust_2018_idioms, unreachable_pub)]
36
37mod decoder;
38mod encoder;
39mod event;
40mod handshake;
41mod lines;
42mod message;
43
44pub use decoder::{decode, Decoder};
45pub use encoder::{encode, Encoder, Sender};
46pub use event::Event;
47pub use handshake::upgrade;
48pub use message::Message;
49
50pub(crate) use lines::Lines;