tokio_stream_util/try_stream/
mod.rs1mod ext;
4pub use ext::*;
5
6use core::{
7 pin::Pin,
8 result::Result,
9 task::{Context, Poll},
10};
11use tokio_stream::Stream;
12
13mod private_try_stream {
14 use super::Stream;
15
16 pub trait Sealed {}
17
18 impl<S, T, E> Sealed for S where S: ?Sized + Stream<Item = Result<T, E>> {}
19}
20
21pub trait TryStream: Stream + private_try_stream::Sealed {
24 type Ok;
26
27 type Error;
29
30 fn try_poll_next(
36 self: Pin<&mut Self>,
37 cx: &mut Context<'_>,
38 ) -> Poll<Option<Result<Self::Ok, Self::Error>>>;
39}
40
41impl<S, T, E> TryStream for S
42where
43 S: ?Sized + Stream<Item = Result<T, E>>,
44{
45 type Ok = T;
46 type Error = E;
47
48 fn try_poll_next(
49 self: Pin<&mut Self>,
50 cx: &mut Context<'_>,
51 ) -> Poll<Option<Result<Self::Ok, Self::Error>>> {
52 self.poll_next(cx)
53 }
54}