1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! `eventsrc` is the small public facade for this workspace.
//!
//! The crate keeps two SSE consumption modes explicit:
//!
//! - [`oneshot::EventSource`] for one-shot API streaming
//! - [`replayable::EventSource`] for reconnecting request replay
//!
//! For lower-level protocol access, use the re-exported `eventsrc-core` types
//! such as [`EventStream`] and [`FrameStream`].
//!
//! # One-Shot Mode
//!
//! The facade re-exports mode APIs, but does not directly depend on `reqwest`.
//! These examples are illustrative; compile-checked reqwest examples live in
//! `eventsrc-client`.
//!
//! ```ignore
//! use eventsrc::oneshot::EventSourceExt as _;
//! use futures_util::StreamExt;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let response = reqwest::Client::new()
//! .get("https://example.com/v1/stream")
//! .send()
//! .await?;
//!
//! let mut stream = response.event_source()?;
//!
//! while let Some(event) = stream.next().await {
//! let event = event?;
//! println!("{}", event.data());
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! # Reconnecting Mode
//!
//! ```ignore
//! use eventsrc::replayable::{ConstantBackoff, EventSourceExt as _};
//! use futures_util::StreamExt;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut stream = reqwest::Client::new()
//! .get("https://example.com/events")
//! .event_source()?
//! .with_retry_policy(ConstantBackoff::new(Duration::from_secs(1)));
//!
//! while let Some(event) = stream.next().await {
//! let event = event?;
//! println!("{}", event.data());
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! # Retry Policies
//!
//! Replayable mode accepts any [`replayable::RetryPolicy`] implementation.
//! The facade re-exports three built-in choices:
//!
//! - [`replayable::ConstantBackoff`] for a fixed delay between reconnects
//! - [`replayable::ExponentialBackoff`] for increasing delays after failures
//! - [`replayable::NeverRetry`] to disable reconnect entirely
pub use eventsrc_client as client;
pub use *;