use core::task;
use std::{
pin::Pin,
task::{Context, Poll},
};
use futures_core::Stream;
use pin_project::pin_project;
use crate::LendingStream;
#[derive(Debug)]
#[pin_project]
pub struct LendMut<I: Stream>(#[pin] I);
impl<I: Stream> LendMut<I> {
pub(crate) fn new(i: I) -> Self {
Self(i)
}
}
impl<I: Stream + Unpin> LendingStream for LendMut<I> {
type Item<'a> = (&'a mut I, I::Item)
where
Self: 'a;
fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item<'_>>> {
let item = task::ready!(Pin::new(&mut self.0).poll_next(cx));
Poll::Ready(item.map(move |item| (&mut self.0, item)))
}
}