1 use crate::stream::{Next, Stream};
2 
3 use core::future::Future;
4 use core::pin::Pin;
5 use core::task::{Context, Poll};
6 
7 /// Future for the [`try_next`](super::StreamExt::try_next) method.
8 #[derive(Debug)]
9 #[must_use = "futures do nothing unless you `.await` or poll them"]
10 pub struct TryNext<'a, St: ?Sized> {
11     inner: Next<'a, St>,
12 }
13 
14 impl<St: ?Sized + Unpin> Unpin for TryNext<'_, St> {}
15 
16 impl<'a, St: ?Sized> TryNext<'a, St> {
new(stream: &'a mut St) -> Self17     pub(super) fn new(stream: &'a mut St) -> Self {
18         Self {
19             inner: Next::new(stream),
20         }
21     }
22 }
23 
24 impl<T, E, St: ?Sized + Stream<Item = Result<T, E>> + Unpin> Future for TryNext<'_, St> {
25     type Output = Result<Option<T>, E>;
26 
poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>27     fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
28         Pin::new(&mut self.inner).poll(cx).map(Option::transpose)
29     }
30 }
31