2018-08-27 12:24:51 -07:00
|
|
|
use futures::Stream;
|
|
|
|
|
|
2018-09-26 10:10:47 -07:00
|
|
|
use std::future::Future;
|
|
|
|
|
use std::pin::Pin;
|
2019-04-11 01:14:31 +09:00
|
|
|
use std::task::{Context, Poll};
|
2018-08-27 12:24:51 -07:00
|
|
|
|
|
|
|
|
/// A future of the next element of a stream.
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Next<'a, T: 'a> {
|
|
|
|
|
stream: &'a mut T,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, T: Stream + Unpin> Unpin for Next<'a, T> {}
|
|
|
|
|
|
|
|
|
|
impl<'a, T: Stream + Unpin> Next<'a, T> {
|
|
|
|
|
pub(super) fn new(stream: &'a mut T) -> Next<'a, T> {
|
|
|
|
|
Next { stream }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, T: Stream + Unpin> Future for Next<'a, T> {
|
|
|
|
|
type Output = Option<Result<T::Item, T::Error>>;
|
|
|
|
|
|
2019-04-11 01:14:31 +09:00
|
|
|
fn poll(mut self: Pin<&mut Self>, _context: &mut Context) -> Poll<Self::Output> {
|
2018-09-26 10:10:47 -07:00
|
|
|
use crate::compat::forward::convert_poll_stream;
|
2018-08-27 12:24:51 -07:00
|
|
|
|
2018-09-26 10:10:47 -07:00
|
|
|
convert_poll_stream(self.stream.poll())
|
2018-08-27 12:24:51 -07:00
|
|
|
}
|
|
|
|
|
}
|