1use crate::fs::{Dir, File, FileType, Metadata, OpenOptions};
2#[cfg(not(windows))]
3use rustix::fs::DirEntryExt;
4use std::ffi::OsString;
5use std::{fmt, io};
6
7pub struct DirEntry {
22 pub(crate) inner: cap_primitives::fs::DirEntry,
23}
24
25impl DirEntry {
26 #[inline]
28 pub fn open(&self) -> io::Result<File> {
29 let file = self.inner.open()?;
30 Ok(File::from_std(file))
31 }
32
33 #[inline]
35 pub fn open_with(&self, options: &OpenOptions) -> io::Result<File> {
36 let file = self.inner.open_with(options)?;
37 Ok(File::from_std(file))
38 }
39
40 #[inline]
42 pub fn open_dir(&self) -> io::Result<Dir> {
43 let dir = self.inner.open_dir()?;
44 Ok(Dir::from_std_file(dir))
45 }
46
47 #[inline]
49 pub fn remove_file(&self) -> io::Result<()> {
50 self.inner.remove_file()
51 }
52
53 #[inline]
55 pub fn remove_dir(&self) -> io::Result<()> {
56 self.inner.remove_dir()
57 }
58
59 #[inline]
63 pub fn metadata(&self) -> io::Result<Metadata> {
64 self.inner.metadata()
65 }
66
67 #[inline]
71 pub fn file_type(&self) -> io::Result<FileType> {
72 self.inner.file_type()
73 }
74
75 #[inline]
80 pub fn file_name(&self) -> OsString {
81 self.inner.file_name()
82 }
83}
84
85#[cfg(not(windows))]
86impl DirEntryExt for DirEntry {
87 #[inline]
88 fn ino(&self) -> u64 {
89 self.inner.ino()
90 }
91}
92
93#[cfg(windows)]
94#[doc(hidden)]
95impl cap_primitives::fs::_WindowsDirEntryExt for DirEntry {
96 #[inline]
97 fn full_metadata(&self) -> io::Result<Metadata> {
98 cap_primitives::fs::_WindowsDirEntryExt::full_metadata(&self.inner)
99 }
100}
101
102impl fmt::Debug for DirEntry {
103 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104 self.inner.fmt(f)
105 }
106}