async_iterator/iter/
lend.rs

1use crate::{Iterator, LendingIterator};
2
3/// The iterator returned from `AsyncIterator::lend`.
4#[derive(Debug)]
5pub struct Lend<I: Iterator>(I);
6
7impl<I: Iterator> Lend<I> {
8    pub(crate) fn new(i: I) -> Self {
9        Self(i)
10    }
11}
12
13impl<I: Iterator> LendingIterator for Lend<I> {
14    type Item<'a> = (&'a I, I::Item)
15    where
16        Self: 'a;
17
18    async fn next(&mut self) -> Option<Self::Item<'_>> {
19        let item = self.0.next().await;
20        item.map(move |item| (&self.0, item))
21    }
22}