cap_std/fs_utf8/
read_dir.rs

1use crate::fs_utf8::DirEntry;
2use std::{fmt, io};
3
4/// Iterator over the entries in a directory.
5///
6/// This corresponds to [`std::fs::ReadDir`].
7///
8/// There is no `from_std` method, as `std::fs::ReadDir` doesn't provide a way
9/// to construct a `ReadDir` without opening directories by ambient paths.
10pub struct ReadDir {
11    cap_std: crate::fs::ReadDir,
12}
13
14impl ReadDir {
15    /// Constructs a new instance of `Self` from the given `cap_std::fs::File`.
16    #[inline]
17    pub fn from_cap_std(cap_std: crate::fs::ReadDir) -> Self {
18        Self { cap_std }
19    }
20}
21
22impl Iterator for ReadDir {
23    type Item = io::Result<DirEntry>;
24
25    #[inline]
26    fn next(&mut self) -> Option<Self::Item> {
27        self.cap_std
28            .next()
29            .map(|result| result.map(DirEntry::from_cap_std))
30    }
31}
32
33impl fmt::Debug for ReadDir {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        self.cap_std.fmt(f)
36    }
37}