3 use std::error::Error as StdError;
5 use std::task::{Context, Poll};
9 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
10 fn size_hint(&self) -> (usize, Option<usize>) {
15 pub trait TryStream: Stream {
22 ) -> Poll<Option<Result<Self::Ok, Self::Error>>>;
25 impl<S, T, E> TryStream for S
27 S: ?Sized + Stream<Item = Result<T, E>>,
35 ) -> Poll<Option<Result<Self::Ok, Self::Error>>> {
40 pub trait ServerSentEvent: Sized + Send + Sync + 'static {}
42 impl<T: Send + Sync + 'static> ServerSentEvent for T {}
44 struct SseKeepAlive<S> {
48 struct SseComment<T>(T);
50 impl<S> Stream for SseKeepAlive<S>
52 S: TryStream + Send + 'static,
53 S::Ok: ServerSentEvent,
54 S::Error: StdError + Send + Sync + 'static,
56 type Item = Result<SseComment<&'static str>, ()>;
57 fn poll_next(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Option<Self::Item>> {
64 ) -> impl TryStream<Ok = impl ServerSentEvent + Send + 'static, Error = ()> + Send + 'static
66 S: TryStream + Send + 'static,
67 S::Ok: ServerSentEvent + Send,
68 S::Error: StdError + Send + Sync + 'static,
70 SseKeepAlive { event_stream }