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