1use ordered_hash_map::ordered_map;
2
3use core::fmt;
4use core::iter::FusedIterator;
5
6pub struct Iter<'a, K, V> {
13 inner: ordered_map::Iter<'a, K, V>,
14}
15
16impl<K, V> Clone for Iter<'_, K, V> {
17 fn clone(&self) -> Self {
18 Self {
19 inner: self.inner.clone(),
20 }
21 }
22}
23
24impl<K, V> fmt::Debug for Iter<'_, K, V>
25where
26 K: fmt::Debug,
27 V: fmt::Debug,
28{
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 self.inner.fmt(f)
31 }
32}
33
34impl<'a, K, V> Iterator for Iter<'a, K, V> {
35 type Item = (&'a K, &'a V);
36
37 #[inline]
38 fn next(&mut self) -> Option<Self::Item> {
39 self.inner.next()
40 }
41
42 #[inline]
43 fn size_hint(&self) -> (usize, Option<usize>) {
44 self.inner.size_hint()
45 }
46}
47
48impl<K, V> DoubleEndedIterator for Iter<'_, K, V> {
49 #[inline]
50 fn next_back(&mut self) -> Option<Self::Item> {
51 self.inner.next_back()
52 }
53}
54
55impl<K, V> ExactSizeIterator for Iter<'_, K, V> {}
56
57impl<K, V> FusedIterator for Iter<'_, K, V> {}
58
59impl<'a, K, V, const N: usize, F, S> IntoIterator for &'a super::EvictingCacheMap<K, V, N, F, S>
60where
61 F: Fn(K, V),
62{
63 type Item = (&'a K, &'a V);
64 type IntoIter = Iter<'a, K, V>;
65
66 fn into_iter(self) -> Self::IntoIter {
67 Self::IntoIter {
68 inner: self.inner.iter(),
69 }
70 }
71}
72
73pub struct IterMut<'a, K, V> {
82 inner: ordered_map::IterMut<'a, K, V>,
83}
84
85impl<K, V> fmt::Debug for IterMut<'_, K, V>
86where
87 K: fmt::Debug,
88 V: fmt::Debug,
89{
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 self.inner.fmt(f)
92 }
93}
94
95impl<'a, K, V> Iterator for IterMut<'a, K, V> {
96 type Item = (&'a K, &'a mut V);
97
98 #[inline]
99 fn next(&mut self) -> Option<Self::Item> {
100 self.inner.next()
101 }
102
103 #[inline]
104 fn size_hint(&self) -> (usize, Option<usize>) {
105 self.inner.size_hint()
106 }
107}
108
109impl<K, V> DoubleEndedIterator for IterMut<'_, K, V> {
110 #[inline]
111 fn next_back(&mut self) -> Option<Self::Item> {
112 self.inner.next_back()
113 }
114}
115
116impl<K, V> ExactSizeIterator for IterMut<'_, K, V> {}
117
118impl<K, V> FusedIterator for IterMut<'_, K, V> {}
119
120impl<'a, K, V, const N: usize, F, S> IntoIterator for &'a mut super::EvictingCacheMap<K, V, N, F, S>
121where
122 F: Fn(K, V),
123{
124 type Item = (&'a K, &'a mut V);
125 type IntoIter = IterMut<'a, K, V>;
126
127 fn into_iter(self) -> Self::IntoIter {
128 Self::IntoIter {
129 inner: self.inner.iter_mut(),
130 }
131 }
132}