eventsrc_client/replayable/connector.rs
1use std::fmt::Debug;
2
3use bytes::Bytes;
4use futures_core::{future::BoxFuture, stream::BoxStream};
5
6use crate::error::Error;
7
8/// An erased byte stream used by backend-neutral replayable connectors.
9pub type BoxBodyStream = BoxStream<'static, Result<Bytes, Error>>;
10
11/// An erased async connection attempt used by backend-neutral replayable connectors.
12pub type ConnectFuture = BoxFuture<'static, Result<BoxBodyStream, Error>>;
13
14/// A backend-specific connector that can establish one SSE connection attempt.
15pub trait Connector: Debug + Send + Sync + 'static {
16 /// Starts a single connection attempt using the current `Last-Event-ID`, if any.
17 fn connect(&self, last_event_id: Option<&str>) -> Result<ConnectFuture, Error>;
18}