async_iterator/iter/
mod.rs1mod lend;
2mod lend_mut;
3mod map;
4
5pub use lend::Lend;
6pub use lend_mut::LendMut;
7pub use map::Map;
8
9use crate::FromIterator;
10
11#[must_use = "iterators are lazy and do nothing unless consumed"]
14pub trait Iterator {
15 type Item;
17
18 async fn next(&mut self) -> Option<Self::Item>;
20
21 fn size_hint(&self) -> (usize, Option<usize>) {
23 (0, None)
24 }
25
26 #[must_use = "iterators do nothing unless iterated over"]
28 fn map<B, F>(self, f: F) -> Map<Self, F>
29 where
30 Self: Sized,
31 F: FnMut(Self::Item) -> B,
32 {
33 Map::new(self, f)
34 }
35
36 #[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
38 async fn collect<B: FromIterator<Self::Item>>(self) -> B
39 where
40 Self: Sized,
41 {
42 let fut = <B as crate::FromIterator<_>>::from_iter(self);
43 fut.await
44 }
45
46 #[must_use = "iterators do nothing unless iterated over"]
49 fn lend(self) -> Lend<Self>
50 where
51 Self: Sized,
52 {
53 Lend::new(self)
54 }
55
56 #[must_use = "iterators do nothing unless iterated over"]
59 fn lend_mut(self) -> LendMut<Self>
60 where
61 Self: Sized,
62 {
63 LendMut::new(self)
64 }
65}