use core::pin::Pin; use futures_core::stream::{FusedStream, Stream, TryStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; use pin_project::pin_project; /// Stream for the [`into_stream`](super::TryStreamExt::into_stream) method. #[pin_project] #[derive(Debug)] #[must_use = "streams do nothing unless polled"] pub struct IntoStream { #[pin] stream: St, } impl IntoStream { #[inline] pub(super) fn new(stream: St) -> Self { IntoStream { stream } } delegate_access_inner!(stream, St, ()); } impl FusedStream for IntoStream { fn is_terminated(&self) -> bool { self.stream.is_terminated() } } impl Stream for IntoStream { type Item = Result; #[inline] fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { self.project().stream.try_poll_next(cx) } fn size_hint(&self) -> (usize, Option) { self.stream.size_hint() } } // Forwarding impl of Sink from the underlying stream #[cfg(feature = "sink")] impl, Item> Sink for IntoStream { type Error = S::Error; delegate_sink!(stream, Item); }