use std::{
io::{Error, Read},
path::Path,
};
use crate::{file::File, open_options::OpenOptions, walkdir::WalkDir, Diskit};
mod sealed
{
pub trait Sealed {}
}
impl<T> sealed::Sealed for T where T: Diskit {}
pub trait DiskitExt: Diskit + sealed::Sealed
{
fn set_pwd<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
{
self.set_pwd_inner(path.as_ref())
}
fn open<P: AsRef<Path>>(&self, path: P) -> Result<File<Self>, Error>
{
self.open_inner(path.as_ref())
}
fn create<P: AsRef<Path>>(&self, path: P) -> Result<File<Self>, Error>
{
self.create_inner(path.as_ref())
}
fn open_with_options<P: AsRef<Path>>(&self, path: P, options: OpenOptions) -> Result<File<Self>, Error>
{
self.open_with_options_inner(path.as_ref(), options)
}
fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
{
self.create_dir_inner(path.as_ref())
}
fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
{
self.create_dir_all_inner(path.as_ref())
}
fn walkdir<P: AsRef<Path>>(&self, path: P) -> WalkDir<Self>
{
self.walkdir_inner(path.as_ref())
}
#[cfg(feature = "trash")]
fn trash_delete<P: AsRef<Path>>(&self, path: P) -> Result<(), trash::Error>
{
self.trash_delete_inner(path.as_ref())
}
fn read_to_end<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>, Error>
{
let mut buf = vec![];
self.open(path)?.read_to_end(&mut buf)?;
Ok(buf)
}
fn read_to_string<P: AsRef<Path>>(&self, path: P) -> Result<String, Error>
{
let mut buf = String::new();
self.open(path)?.read_to_string(&mut buf)?;
Ok(buf)
}
}
impl<T> DiskitExt for T where T: Diskit {}