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