1use core::{fmt, iter::FusedIterator};
4
5macro_rules! iterator {
7 (
8 $(#[$meta:meta])*
9 $name:ident<$($lifetime:lifetime,)? K, V> => $inner:ident, $item:ty $(,)?
10 ) => {
11 $(#[$meta])*
12 pub struct $name<$($lifetime,)? K, V>(pub(crate) indexmap::map::$inner<$($lifetime,)? K, V>);
13
14 impl<$($lifetime,)? K, V> Iterator for $name<$($lifetime,)? K, V> {
15 type Item = $item;
16
17 fn next(&mut self) -> Option<Self::Item> {
18 self.0.next()
19 }
20
21 fn size_hint(&self) -> (usize, Option<usize>) {
22 self.0.size_hint()
23 }
24
25 fn count(self) -> usize {
26 self.0.count()
27 }
28
29 fn nth(&mut self, n: usize) -> Option<Self::Item> {
30 self.0.nth(n)
31 }
32
33 fn last(self) -> Option<Self::Item> {
34 self.0.last()
35 }
36 }
37
38 impl<$($lifetime,)? K, V> DoubleEndedIterator for $name<$($lifetime,)? K, V> {
39 fn next_back(&mut self) -> Option<Self::Item> {
40 self.0.next_back()
41 }
42
43 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
44 self.0.nth_back(n)
45 }
46 }
47
48 impl<$($lifetime,)? K, V> ExactSizeIterator for $name<$($lifetime,)? K, V> {
49 fn len(&self) -> usize {
50 self.0.len()
51 }
52 }
53
54 impl<$($lifetime,)? K, V> FusedIterator for $name<$($lifetime,)? K, V> {}
55
56 impl<$($lifetime,)? K: fmt::Debug, V: fmt::Debug> fmt::Debug for $name<$($lifetime,)? K, V> {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 f.debug_tuple(stringify!($name)).field(&self.0).finish()
59 }
60 }
61 };
62}
63
64macro_rules! clone {
66 ($($name:ident),*) => {
67 $(
68 impl<K, V> Clone for $name<'_, K, V> {
69 fn clone(&self) -> Self {
70 Self(self.0.clone())
71 }
72 }
73 )*
74 };
75}
76
77iterator! {
78 Iter<'a, K, V> => Iter, (&'a K, &'a V),
81}
82
83iterator! {
84 IterMut<'a, K, V> => IterMut, (&'a K, &'a mut V),
87}
88
89iterator! {
90 IntoIter<K, V> => IntoIter, (K, V),
93}
94
95iterator! {
96 Keys<'a, K, V> => Keys, &'a K,
98}
99
100iterator! {
101 Values<'a, K, V> => Values, &'a V,
103}
104
105iterator! {
106 ValuesMut<'a, K, V> => ValuesMut, &'a mut V,
109}
110
111iterator! {
112 IntoKeys<K, V> => IntoKeys, K,
115}
116
117iterator! {
118 IntoValues<K, V> => IntoValues, V,
121}
122
123clone!(Iter, Keys, Values);