micromap_rawl/set/
iterators.rs1use crate::set::{Set, SetIntoIter, SetIter};
2use core::iter::FusedIterator;
3
4impl<T: PartialEq, const N: usize> Set<T, N> {
5 #[inline]
7 #[must_use]
8 pub fn iter(&self) -> SetIter<T> {
9 SetIter {
10 iter: self.map.keys(),
11 }
12 }
13}
14
15impl<'a, T> Iterator for SetIter<'a, T> {
16 type Item = &'a T;
17
18 #[inline]
19 #[must_use]
20 fn next(&mut self) -> Option<Self::Item> {
21 self.iter.next()
22 }
23
24 #[inline]
25 fn size_hint(&self) -> (usize, Option<usize>) {
26 self.iter.size_hint()
27 }
28}
29
30impl<T: PartialEq, const N: usize> Iterator for SetIntoIter<T, N> {
31 type Item = T;
32
33 #[inline]
34 #[must_use]
35 fn next(&mut self) -> Option<Self::Item> {
36 self.iter.next()
37 }
38
39 #[inline]
40 fn size_hint(&self) -> (usize, Option<usize>) {
41 self.iter.size_hint()
42 }
43}
44
45impl<'a, T: PartialEq, const N: usize> IntoIterator for &'a Set<T, N> {
46 type Item = &'a T;
47 type IntoIter = SetIter<'a, T>;
48
49 #[inline]
50 #[must_use]
51 fn into_iter(self) -> Self::IntoIter {
52 self.iter()
53 }
54}
55
56impl<T: PartialEq, const N: usize> IntoIterator for Set<T, N> {
57 type Item = T;
58 type IntoIter = SetIntoIter<T, N>;
59
60 #[inline]
61 #[must_use]
62 fn into_iter(self) -> Self::IntoIter {
63 SetIntoIter {
64 iter: self.map.into_keys(),
65 }
66 }
67}
68
69impl<T> ExactSizeIterator for SetIter<'_, T> {
70 fn len(&self) -> usize {
71 self.iter.len()
72 }
73}
74
75impl<T: PartialEq, const N: usize> ExactSizeIterator for SetIntoIter<T, N> {
76 fn len(&self) -> usize {
77 self.iter.len()
78 }
79}
80
81impl<T> FusedIterator for SetIter<'_, T> {}
82
83impl<T: PartialEq, const N: usize> FusedIterator for SetIntoIter<T, N> {}