1mod lend;
2mod lend_mut;
3mod map;
45pub use lend::Lend;
6pub use lend_mut::LendMut;
7pub use map::Map;
89use crate::FromIterator;
1011/// An interface for dealing with iterators.
1213#[must_use = "iterators are lazy and do nothing unless consumed"]
14pub trait Iterator {
15/// The type of the elements being iterated over.
16type Item;
1718/// Advances the iterator and returns the next value.
19async fn next(&mut self) -> Option<Self::Item>;
2021/// Returns the bounds on the remaining length of the iterator.
22fn size_hint(&self) -> (usize, Option<usize>) {
23 (0, None)
24 }
2526/// Takes a closure and creates an iterator which calls that closure on each element.
27#[must_use = "iterators do nothing unless iterated over"]
28fn map<B, F>(self, f: F) -> Map<Self, F>
29where
30Self: Sized,
31 F: FnMut(Self::Item) -> B,
32 {
33 Map::new(self, f)
34 }
3536/// Transforms an iterator into a collection.
37#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
38async fn collect<B: FromIterator<Self::Item>>(self) -> B
39where
40Self: Sized,
41 {
42let fut = <B as crate::FromIterator<_>>::from_iter(self);
43 fut.await
44}
4546/// Creates an iterator which yields a reference to `self` as well as
47 /// the next value.
48#[must_use = "iterators do nothing unless iterated over"]
49fn lend(self) -> Lend<Self>
50where
51Self: Sized,
52 {
53 Lend::new(self)
54 }
5556/// Creates an iterator which yields a mutable reference to `self` as well
57 /// as the next value.
58#[must_use = "iterators do nothing unless iterated over"]
59fn lend_mut(self) -> LendMut<Self>
60where
61Self: Sized,
62 {
63 LendMut::new(self)
64 }
65}