use crate::stream::TryStreamExt; use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::stream::{FusedStream, TryStream}; use futures_core::task::{Context, Poll}; /// Future for the [`try_next`](super::TryStreamExt::try_next) method. #[derive(Debug)] #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct TryNext<'a, St: ?Sized> { stream: &'a mut St, } impl Unpin for TryNext<'_, St> {} impl<'a, St: ?Sized + TryStream + Unpin> TryNext<'a, St> { pub(super) fn new(stream: &'a mut St) -> Self { Self { stream } } } impl FusedFuture for TryNext<'_, St> { fn is_terminated(&self) -> bool { self.stream.is_terminated() } } impl Future for TryNext<'_, St> { type Output = Result, St::Error>; fn poll( mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll { self.stream.try_poll_next_unpin(cx)?.map(Ok) } }