use async_std::{
fs::{File, OpenOptions},
path::Path,
path::PathBuf,
};
use crate::errors::Error;
pub async fn open<S>(path: &S) -> Result<File, Error>
where
S: AsRef<Path> + ?Sized,
{
File::open(path).await.map_err(|e| {
let p: &Path = path.as_ref();
Error::FileOpen(e, p.to_string_lossy().to_string())
})
}
pub async fn open_with<S>(path: &S, options: &mut OpenOptions) -> Result<File, Error>
where
S: AsRef<Path> + ?Sized,
{
options.open(path).await.map_err(|e| {
let p: &Path = path.as_ref();
Error::FileOpen(e, p.to_string_lossy().to_string())
})
}
pub async fn create<S>(path: &S) -> Result<File, Error>
where
S: AsRef<Path> + ?Sized,
{
File::create(path).await.map_err(|e| {
let p: &Path = path.as_ref();
Error::FileCreate(e, p.to_string_lossy().to_string())
})
}
pub async fn canonicalize<S>(path: &S) -> Result<PathBuf, Error>
where
S: AsRef<Path> + ?Sized,
{
async_std::fs::canonicalize(path).await.map_err(|e| {
let p: &Path = path.as_ref();
Error::FileCanonicalize(e, p.to_string_lossy().to_string())
})
}
pub use crate::file::extension;