use futures_core::Stream; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; // This is equivalent to the `futures::StreamExt::next` method. // But we want to make this crate dependency as small as possible, so we define our `next` function. #[doc(hidden)] pub fn next(stream: &mut S) -> impl Future> + '_ where S: Stream + Unpin, { Next { stream } } #[derive(Debug)] struct Next<'a, S> { stream: &'a mut S, } impl Unpin for Next<'_, S> where S: Unpin {} impl Future for Next<'_, S> where S: Stream + Unpin, { type Output = Option; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { Pin::new(&mut self.stream).poll_next(cx) } }