1 use crate::Stream; 2 3 use core::future::Future; 4 use core::marker::PhantomPinned; 5 use core::pin::Pin; 6 use core::task::{Context, Poll}; 7 use pin_project_lite::pin_project; 8 9 pin_project! { 10 /// Future for the [`next`](super::StreamExt::next) method. 11 #[derive(Debug)] 12 #[must_use = "futures do nothing unless you `.await` or poll them"] 13 pub struct Next<'a, St: ?Sized> { 14 stream: &'a mut St, 15 // Make this future `!Unpin` for compatibility with async trait methods. 16 #[pin] 17 _pin: PhantomPinned, 18 } 19 } 20 21 impl<'a, St: ?Sized> Next<'a, St> { new(stream: &'a mut St) -> Self22 pub(super) fn new(stream: &'a mut St) -> Self { 23 Next { 24 stream, 25 _pin: PhantomPinned, 26 } 27 } 28 } 29 30 impl<St: ?Sized + Stream + Unpin> Future for Next<'_, St> { 31 type Output = Option<St::Item>; 32 poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>33 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 34 let me = self.project(); 35 Pin::new(me.stream).poll_next(cx) 36 } 37 } 38