mezzaluna_loaded_features/loaded_features/
iter.rs

1use core::iter::FusedIterator;
2use core::slice;
3use std::collections::hash_set;
4use std::path::{Path, PathBuf};
5
6use crate::Feature;
7
8/// An iterator over the feature paths in a `LoadedFeatures`.
9///
10/// This struct is created by the [`iter`] method on [`LoadedFeatures`]. See its
11/// documentation for more.
12///
13/// [`iter`]: super::LoadedFeatures::iter
14/// [`LoadedFeatures`]: super::LoadedFeatures
15#[derive(Debug, Clone)]
16pub struct Iter<'a> {
17    pub(crate) inner: slice::Iter<'a, PathBuf>,
18}
19
20impl<'a> Iterator for Iter<'a> {
21    type Item = &'a Path;
22
23    fn next(&mut self) -> Option<Self::Item> {
24        let next = self.inner.next()?;
25        Some(&**next)
26    }
27
28    fn nth(&mut self, n: usize) -> Option<Self::Item> {
29        let nth = self.inner.nth(n)?;
30        Some(&**nth)
31    }
32
33    fn size_hint(&self) -> (usize, Option<usize>) {
34        self.inner.size_hint()
35    }
36
37    fn count(self) -> usize {
38        self.inner.count()
39    }
40
41    fn last(self) -> Option<Self::Item> {
42        let last = self.inner.last()?;
43        Some(&**last)
44    }
45}
46
47impl ExactSizeIterator for Iter<'_> {
48    fn len(&self) -> usize {
49        self.inner.len()
50    }
51}
52
53impl FusedIterator for Iter<'_> {}
54
55/// An iterator over the features in a `LoadedFeatures`.
56///
57/// This struct is created by the [`features`] method on [`LoadedFeatures`]. See
58/// its documentation for more.
59///
60/// [`features`]: super::LoadedFeatures::features
61/// [`LoadedFeatures`]: super::LoadedFeatures
62#[derive(Debug, Clone)]
63pub struct Features<'a> {
64    pub(crate) inner: hash_set::Iter<'a, Feature>,
65}
66
67impl<'a> Iterator for Features<'a> {
68    type Item = &'a Feature;
69
70    fn next(&mut self) -> Option<Self::Item> {
71        self.inner.next()
72    }
73
74    fn nth(&mut self, n: usize) -> Option<Self::Item> {
75        self.inner.nth(n)
76    }
77
78    fn count(self) -> usize {
79        self.inner.count()
80    }
81
82    fn size_hint(&self) -> (usize, Option<usize>) {
83        self.inner.size_hint()
84    }
85
86    fn last(self) -> Option<Self::Item> {
87        self.inner.last()
88    }
89}
90
91impl ExactSizeIterator for Features<'_> {
92    fn len(&self) -> usize {
93        self.inner.len()
94    }
95}
96
97impl FusedIterator for Features<'_> {}