1use core::{
4 marker::PhantomData,
5 slice::{self, Iter},
6};
7
8use alloc::vec::{self, IntoIter};
9
10use crate::allocator::Allocator;
11
12#[derive(Debug)]
15#[must_use]
16pub struct Drain<'a, K, V, A: Allocator> {
17 #[cfg(feature = "allocator_api")]
18 pub(crate) iter: vec::Drain<'a, (K, V), A>,
20 #[cfg(not(feature = "allocator_api"))]
21 pub(crate) iter: vec::Drain<'a, (K, V)>,
23 pub(crate) phantom: PhantomData<A>,
25}
26
27impl<K, V, A: Allocator> Iterator for Drain<'_, K, V, A> {
28 type Item = (K, V);
29
30 #[inline]
31 fn next(&mut self) -> Option<Self::Item> {
32 self.iter.next()
33 }
34}
35
36#[allow(clippy::module_name_repetitions)]
38#[derive(Debug)]
41#[must_use]
42pub struct IterMut<'a, K, V>(pub(crate) slice::IterMut<'a, (K, V)>);
43
44impl<'a, K, V> Iterator for IterMut<'a, K, V> {
45 type Item = (&'a K, &'a mut V);
46
47 #[inline]
48 fn next(&mut self) -> Option<Self::Item> {
49 self.0.next().map(|(key, value)| (&*key, value))
50 }
51}
52
53#[derive(Debug)]
56#[must_use]
57pub struct Keys<'a, K, V>(pub(crate) Iter<'a, (K, V)>);
58
59impl<'a, K, V> Iterator for Keys<'a, K, V> {
60 type Item = &'a K;
61
62 #[inline]
63 fn next(&mut self) -> Option<Self::Item> {
64 self.0.next().map(|(key, _value)| key)
65 }
66}
67
68#[derive(Debug)]
71#[must_use]
72pub struct IntoKeys<K, V, A: Allocator> {
73 #[cfg(feature = "allocator_api")]
74 pub(crate) iter: IntoIter<(K, V), A>,
76 #[cfg(not(feature = "allocator_api"))]
77 pub(crate) iter: IntoIter<(K, V)>,
79 pub(crate) phantom: PhantomData<A>,
81}
82
83impl<K, V, A: Allocator> Iterator for IntoKeys<K, V, A> {
84 type Item = K;
85
86 #[inline]
87 fn next(&mut self) -> Option<Self::Item> {
88 self.iter.next().map(|(key, _value)| key)
89 }
90}
91
92#[derive(Debug)]
95#[must_use]
96pub struct Values<'a, K, V>(pub(crate) Iter<'a, (K, V)>);
97
98impl<'a, K, V> Iterator for Values<'a, K, V> {
99 type Item = &'a V;
100
101 #[inline]
102 fn next(&mut self) -> Option<Self::Item> {
103 self.0.next().map(|(_key, value)| value)
104 }
105}
106
107#[derive(Debug)]
110#[must_use]
111pub struct ValuesMut<'a, K, V>(pub(crate) slice::IterMut<'a, (K, V)>);
112
113impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
114 type Item = &'a mut V;
115
116 #[inline]
117 fn next(&mut self) -> Option<Self::Item> {
118 self.0.next().map(|(_key, value)| value)
119 }
120}
121
122#[derive(Debug)]
125#[must_use]
126pub struct IntoValues<K, V, A: Allocator> {
127 #[cfg(feature = "allocator_api")]
128 pub(crate) iter: IntoIter<(K, V), A>,
130 #[cfg(not(feature = "allocator_api"))]
131 pub(crate) iter: IntoIter<(K, V)>,
133 pub(crate) phantom: PhantomData<A>,
135}
136
137impl<K, V, A: Allocator> Iterator for IntoValues<K, V, A> {
138 type Item = V;
139
140 #[inline]
141 fn next(&mut self) -> Option<Self::Item> {
142 self.iter.next().map(|(_key, value)| value)
143 }
144}