cap_async_std/fs/
dir_entry.rs1use crate::fs::{Dir, File, FileType, Metadata, OpenOptions};
2use async_std::io;
3#[cfg(unix)]
4use async_std::os::unix::fs::DirEntryExt;
5#[cfg(target_os = "wasi")]
6use async_std::os::wasi::fs::DirEntryExt;
7use std::ffi::OsString;
8use std::fmt;
9
10pub struct DirEntry {
28 pub(crate) inner: cap_primitives::fs::DirEntry,
29}
30
31impl DirEntry {
32 #[inline]
34 pub fn open(&self) -> io::Result<File> {
35 let file = self.inner.open()?.into();
36 Ok(File::from_std(file))
37 }
38
39 #[inline]
41 pub fn open_with(&self, options: &OpenOptions) -> io::Result<File> {
42 let file = self.inner.open_with(options)?.into();
43 Ok(File::from_std(file))
44 }
45
46 #[inline]
48 pub fn open_dir(&self) -> io::Result<Dir> {
49 let file = self.inner.open_dir()?.into();
50 Ok(Dir::from_std_file(file))
51 }
52
53 #[inline]
55 pub fn remove_file(&self) -> io::Result<()> {
56 self.inner.remove_file()
57 }
58
59 #[inline]
61 pub fn remove_dir(&self) -> io::Result<()> {
62 self.inner.remove_dir()
63 }
64
65 #[inline]
69 pub fn metadata(&self) -> io::Result<Metadata> {
70 self.inner.metadata()
72 }
73
74 #[inline]
78 pub async fn file_type(&self) -> io::Result<FileType> {
79 self.inner.file_type()
81 }
82
83 #[inline]
88 pub fn file_name(&self) -> OsString {
89 self.inner.file_name()
90 }
91}
92
93#[cfg(not(windows))]
94impl DirEntryExt for DirEntry {
95 #[inline]
96 fn ino(&self) -> u64 {
97 self.inner.ino()
98 }
99}
100
101#[cfg(windows)]
102#[doc(hidden)]
103impl cap_primitives::fs::_WindowsDirEntryExt for DirEntry {
104 #[inline]
105 fn full_metadata(&self) -> io::Result<Metadata> {
106 self.inner.full_metadata()
107 }
108}
109
110impl fmt::Debug for DirEntry {
111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112 self.inner.fmt(f)
113 }
114}