1use futures_core::Stream;
2use std::future::Future;
3use std::pin::Pin;
4use std::task::{Context, Poll};
5
6// This is equivalent to the `futures::StreamExt::next` method.
7// But we want to make this crate dependency as small as possible, so we define our `next` function.
8#[doc(hidden)]
9pub fn next<S>(stream: &mut S) -> impl Future<Output = Option<S::Item>> + '_
10where
11 S: Stream + Unpin,
12{
13 Next { stream }
14}
15
16#[derive(Debug)]
17struct Next<'a, S> {
18 stream: &'a mut S,
19}
20
21impl<S> Unpin for Next<'_, S> where S: Unpin {}
22
23impl<S> Future for Next<'_, S>
24where
25 S: Stream + Unpin,
26{
27 type Output = Option<S::Item>;
28
29 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
30 Pin::new(&mut self.stream).poll_next(cx)
31 }
32}
33