cap_std/fs/
read_dir.rs

1use crate::fs::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    pub(crate) inner: cap_primitives::fs::ReadDir,
12}
13
14impl Iterator for ReadDir {
15    type Item = io::Result<DirEntry>;
16
17    #[inline]
18    fn next(&mut self) -> Option<Self::Item> {
19        self.inner
20            .next()
21            .map(|inner| inner.map(|inner| DirEntry { inner }))
22    }
23}
24
25impl fmt::Debug for ReadDir {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        self.inner.fmt(f)
28    }
29}