async_iterator/iter/
map.rs1use crate::Iterator;
2use core::future::Future;
3
4#[derive(Debug)]
6pub struct Map<I, F> {
7 stream: I,
8 f: F,
9}
10
11impl<I, F> Map<I, F> {
12 pub(crate) fn new(stream: I, f: F) -> Self {
13 Self { stream, f }
14 }
15}
16
17impl<I, F, B, Fut> Iterator for Map<I, F>
18where
19 I: Iterator,
20 F: FnMut(I::Item) -> Fut,
21 Fut: Future<Output = B>,
22{
23 type Item = B;
24
25 async fn next(&mut self) -> Option<Self::Item> {
26 let item = self.stream.next().await?;
27 let out = (self.f)(item).await;
28 Some(out)
29 }
30}