lending_stream/
lend_mut.rs1use core::task;
2use std::{
3 pin::Pin,
4 task::{Context, Poll},
5};
6
7use futures_core::Stream;
8use pin_project::pin_project;
9
10use crate::LendingStream;
11
12#[derive(Debug)]
14#[pin_project]
15pub struct LendMut<I: Stream>(#[pin] I);
16
17impl<I: Stream> LendMut<I> {
18 pub(crate) fn new(i: I) -> Self {
19 Self(i)
20 }
21}
22
23impl<I: Stream + Unpin> LendingStream for LendMut<I> {
24 type Item<'a> = (&'a mut I, I::Item)
25 where
26 Self: 'a;
27
28 fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item<'_>>> {
29 let item = task::ready!(Pin::new(&mut self.0).poll_next(cx));
30 Poll::Ready(item.map(move |item| (&mut self.0, item)))
31 }
32}