cap_async_std/fs/
read_dir.rs

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