1use std::path::Path;
4use std::path::PathBuf;
5
6#[cfg(feature = "enhanced-errors")]
8pub use crate::deps::enhanced_errors::ReadDir;
9
10#[cfg(not(feature = "enhanced-errors"))]
11pub use std::fs::ReadDir;
12
13pub use std::fs::Metadata;
15
16pub fn create_file<P: Into<PathBuf> + std::convert::AsRef<std::path::Path>>(
22 path: P,
23) -> std::io::Result<()> {
24 #[cfg(feature = "enhanced-errors")]
25 crate::deps::enhanced_errors::File::create(path)?;
26
27 #[cfg(not(feature = "enhanced-errors"))]
28 ::std::fs::File::create(path)?;
29
30 Ok(())
31}
32
33pub fn rename<From: AsRef<Path>, To: AsRef<Path>>(from: From, to: To) -> std::io::Result<()> {
40 #[cfg(feature = "enhanced-errors")]
41 crate::deps::enhanced_errors::rename(from, to)?;
42
43 #[cfg(not(feature = "enhanced-errors"))]
44 ::std::fs::rename(from, to)?;
45
46 Ok(())
47}
48
49pub fn set_permissions<P: AsRef<Path>>(
55 path: P,
56 perms: std::fs::Permissions,
57) -> std::io::Result<()> {
58 #[cfg(feature = "enhanced-errors")]
59 crate::deps::enhanced_errors::set_permissions(path, perms)?;
60
61 #[cfg(not(feature = "enhanced-errors"))]
62 std::fs::set_permissions(path, perms)?;
63
64 Ok(())
65}
66
67pub fn create_dir<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
73 #[cfg(feature = "enhanced-errors")]
74 {
75 crate::deps::enhanced_errors::create_dir(path)
76 }
77 #[cfg(not(feature = "enhanced-errors"))]
78 {
79 std::fs::create_dir(path)
80 }
81}
82
83pub fn create_dir_all<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
89 #[cfg(feature = "enhanced-errors")]
90 {
91 crate::deps::enhanced_errors::create_dir_all(path)
92 }
93 #[cfg(not(feature = "enhanced-errors"))]
94 {
95 std::fs::create_dir_all(path)
96 }
97}
98
99pub fn remove_dir<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
105 #[cfg(feature = "enhanced-errors")]
106 {
107 crate::deps::enhanced_errors::remove_dir(path)
108 }
109 #[cfg(not(feature = "enhanced-errors"))]
110 {
111 std::fs::remove_dir(path)
112 }
113}
114
115pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
121 #[cfg(feature = "enhanced-errors")]
122 {
123 crate::deps::enhanced_errors::remove_dir_all(path)
124 }
125 #[cfg(not(feature = "enhanced-errors"))]
126 {
127 std::fs::remove_dir_all(path)
128 }
129}
130
131#[cfg(feature = "enhanced-errors")]
137pub fn read_dir<P: AsRef<Path>>(path: P) -> std::io::Result<crate::deps::enhanced_errors::ReadDir> {
138 crate::deps::enhanced_errors::read_dir(path.as_ref())
139}
140
141#[cfg(not(feature = "enhanced-errors"))]
147pub fn read_dir<P: AsRef<Path>>(path: P) -> std::io::Result<std::fs::ReadDir> {
148 std::fs::read_dir(path)
149}
150
151pub fn metadata<P: AsRef<Path>>(path: P) -> std::io::Result<std::fs::Metadata> {
157 #[cfg(feature = "enhanced-errors")]
158 {
159 crate::deps::enhanced_errors::metadata(path)
160 }
161 #[cfg(not(feature = "enhanced-errors"))]
162 {
163 std::fs::metadata(path)
164 }
165}
166
167pub fn read<P: AsRef<Path>>(path: P) -> std::io::Result<Vec<u8>> {
173 #[cfg(feature = "enhanced-errors")]
174 {
175 crate::deps::enhanced_errors::read(path)
176 }
177 #[cfg(not(feature = "enhanced-errors"))]
178 {
179 std::fs::read(path)
180 }
181}
182
183pub fn read_to_string<P: AsRef<Path>>(path: P) -> std::io::Result<String> {
189 #[cfg(feature = "enhanced-errors")]
190 {
191 crate::deps::enhanced_errors::read_to_string(path)
192 }
193 #[cfg(not(feature = "enhanced-errors"))]
194 {
195 std::fs::read_to_string(path)
196 }
197}
198
199pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> std::io::Result<()> {
205 #[cfg(feature = "enhanced-errors")]
206 {
207 crate::deps::enhanced_errors::write(path, contents)
208 }
209 #[cfg(not(feature = "enhanced-errors"))]
210 {
211 std::fs::write(path, contents)
212 }
213}
214
215pub fn remove_file<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
221 #[cfg(feature = "enhanced-errors")]
222 {
223 crate::deps::enhanced_errors::remove_file(path)
224 }
225 #[cfg(not(feature = "enhanced-errors"))]
226 {
227 std::fs::remove_file(path)
228 }
229}