mezzaluna_loaded_features/loaded_features/
iter.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use core::iter::FusedIterator;
use core::slice;
use std::collections::hash_set;
use std::path::{Path, PathBuf};

use crate::Feature;

/// An iterator over the feature paths in a `LoadedFeatures`.
///
/// This struct is created by the [`iter`] method on [`LoadedFeatures`]. See its
/// documentation for more.
///
/// [`iter`]: super::LoadedFeatures::iter
/// [`LoadedFeatures`]: super::LoadedFeatures
#[derive(Debug, Clone)]
pub struct Iter<'a> {
    pub(crate) inner: slice::Iter<'a, PathBuf>,
}

impl<'a> Iterator for Iter<'a> {
    type Item = &'a Path;

    fn next(&mut self) -> Option<Self::Item> {
        let next = self.inner.next()?;
        Some(&**next)
    }

    fn nth(&mut self, n: usize) -> Option<Self::Item> {
        let nth = self.inner.nth(n)?;
        Some(&**nth)
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        self.inner.size_hint()
    }

    fn count(self) -> usize {
        self.inner.count()
    }

    fn last(self) -> Option<Self::Item> {
        let last = self.inner.last()?;
        Some(&**last)
    }
}

impl ExactSizeIterator for Iter<'_> {
    fn len(&self) -> usize {
        self.inner.len()
    }
}

impl FusedIterator for Iter<'_> {}

/// An iterator over the features in a `LoadedFeatures`.
///
/// This struct is created by the [`features`] method on [`LoadedFeatures`]. See
/// its documentation for more.
///
/// [`features`]: super::LoadedFeatures::features
/// [`LoadedFeatures`]: super::LoadedFeatures
#[derive(Debug, Clone)]
pub struct Features<'a> {
    pub(crate) inner: hash_set::Iter<'a, Feature>,
}

impl<'a> Iterator for Features<'a> {
    type Item = &'a Feature;

    fn next(&mut self) -> Option<Self::Item> {
        self.inner.next()
    }

    fn nth(&mut self, n: usize) -> Option<Self::Item> {
        self.inner.nth(n)
    }

    fn count(self) -> usize {
        self.inner.count()
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        self.inner.size_hint()
    }

    fn last(self) -> Option<Self::Item> {
        self.inner.last()
    }
}

impl ExactSizeIterator for Features<'_> {
    fn len(&self) -> usize {
        self.inner.len()
    }
}

impl FusedIterator for Features<'_> {}