1use anyhow::Result;
2use std::path::Path;
3
4#[cfg(feature = "async-io")]
5mod io {
6 use super::*;
7
8 pub async fn write_file(path: &Path, bytes: &[u8]) -> Result<()> {
9 tokio::fs::write(path, bytes).await?;
10 Ok(())
11 }
12
13 pub async fn create_dir_all(path: &Path) -> Result<()> {
14 tokio::fs::create_dir_all(path).await?;
15 Ok(())
16 }
17
18 pub async fn copy(from: &Path, to: &Path) -> Result<u64> {
19 tokio::fs::copy(from, to).await.map_err(Into::into)
20 }
21
22 pub async fn metadata(path: &Path) -> Result<std::fs::Metadata> {
23 tokio::fs::metadata(path).await.map_err(Into::into)
24 }
25}
26
27#[cfg(not(feature = "async-io"))]
28mod io {
29 use super::*;
30
31 pub async fn write_file(path: &Path, bytes: &[u8]) -> Result<()> {
32 std::fs::write(path, bytes)?;
33 Ok(())
34 }
35
36 pub async fn create_dir_all(path: &Path) -> Result<()> {
37 std::fs::create_dir_all(path)?;
38 Ok(())
39 }
40
41 pub async fn copy(from: &Path, to: &Path) -> Result<u64> {
42 Ok(std::fs::copy(from, to)?)
43 }
44
45 pub async fn metadata(path: &Path) -> Result<std::fs::Metadata> {
46 Ok(std::fs::metadata(path)?)
47 }
48}
49
50pub use io::*;