standard_lib/collections/hash/set/
iter.rs1use std::hash::{BuildHasher, Hash};
2use std::iter::FusedIterator;
3
4use super::HashSet;
5use crate::collections::hash::map::{IntoKeys, Keys};
6#[allow(unused)]
7use crate::collections::traits::set::SetIterator;
8
9impl<T: Hash + Eq, B: BuildHasher> IntoIterator for HashSet<T, B> {
10 type Item = T;
11
12 type IntoIter = IntoIter<T>;
13
14 fn into_iter(self) -> Self::IntoIter {
15 IntoIter(self.inner.into_keys())
16 }
17}
18
19pub struct IntoIter<T: Hash + Eq>(pub(crate) IntoKeys<T, ()>);
23
24impl<T: Hash + Eq> Iterator for IntoIter<T> {
25 type Item = T;
26
27 fn next(&mut self) -> Option<Self::Item> {
28 self.0.next()
29 }
30
31 fn size_hint(&self) -> (usize, Option<usize>) {
32 self.0.size_hint()
33 }
34}
35
36impl<T: Hash + Eq> FusedIterator for IntoIter<T> {}
37
38impl<'a, T: Hash + Eq, B: BuildHasher> IntoIterator for &'a HashSet<T, B> {
39 type Item = &'a T;
40
41 type IntoIter = Iter<'a, T>;
42
43 fn into_iter(self) -> Self::IntoIter {
44 Iter(self.inner.keys())
45 }
46}
47
48pub struct Iter<'a, T: Hash + Eq>(pub(crate) Keys<'a, T, ()>);
52
53impl<'a, T: Hash + Eq> Iterator for Iter<'a, T> {
54 type Item = &'a T;
55
56 fn next(&mut self) -> Option<Self::Item> {
57 self.0.next()
58 }
59
60 fn size_hint(&self) -> (usize, Option<usize>) {
61 self.0.size_hint()
62 }
63}
64
65impl<'a, T: Hash + Eq> FusedIterator for Iter<'a, T> {}