#[cfg(any(feature = "mock", test))]
extern crate pseudo;
#[cfg(feature = "temp")]
extern crate rand;
#[cfg(feature = "temp")]
extern crate tempdir;
use std::ffi::OsString;
use std::io::Result;
use std::path::{Path, PathBuf};
#[cfg(feature = "fake")]
pub use fake::{FakeFileSystem, FakeTempDir};
#[cfg(any(feature = "mock", test))]
pub use mock::{FakeError, MockFileSystem};
pub use os::OsFileSystem;
#[cfg(feature = "temp")]
pub use os::OsTempDir;
#[cfg(feature = "fake")]
mod fake;
#[cfg(any(feature = "mock", test))]
mod mock;
mod os;
pub trait FileSystem {
type DirEntry: DirEntry;
type ReadDir: ReadDir<Self::DirEntry>;
fn current_dir(&self) -> Result<PathBuf>;
fn set_current_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool;
fn is_file<P: AsRef<Path>>(&self, path: P) -> bool;
fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn create_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn remove_dir<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn remove_dir_all<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<Self::ReadDir>;
fn create_file<P, B>(&self, path: P, buf: B) -> Result<()>
where
P: AsRef<Path>,
B: AsRef<[u8]>;
fn write_file<P, B>(&self, path: P, buf: B) -> Result<()>
where
P: AsRef<Path>,
B: AsRef<[u8]>;
fn overwrite_file<P, B>(&self, path: P, buf: B) -> Result<()>
where
P: AsRef<Path>,
B: AsRef<[u8]>;
fn read_file<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>;
fn read_file_to_string<P: AsRef<Path>>(&self, path: P) -> Result<String>;
fn remove_file<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn copy_file<P, Q>(&self, from: P, to: Q) -> Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>;
fn rename<P, Q>(&self, from: P, to: Q) -> Result<()>
where
P: AsRef<Path>,
Q: AsRef<Path>;
fn readonly<P: AsRef<Path>>(&self, path: P) -> Result<bool>;
fn set_readonly<P: AsRef<Path>>(&self, path: P, readonly: bool) -> Result<()>;
fn len<P: AsRef<Path>>(&self, path: P) -> u64;
}
#[cfg(unix)]
pub trait UnixFileSystem {
fn mode<P: AsRef<Path>>(&self, path: P) -> Result<u32>;
fn set_mode<P: AsRef<Path>>(&self, path: P, mode: u32) -> Result<()>;
}
#[cfg(feature = "temp")]
pub trait TempDir {
fn path(&self) -> &Path;
}
#[cfg(feature = "temp")]
pub trait TempFileSystem {
type TempDir: TempDir;
fn temp_dir<S: AsRef<str>>(&self, prefix: S) -> Result<Self::TempDir>;
}
pub trait DirEntry {
fn file_name(&self) -> OsString;
fn path(&self) -> PathBuf;
}
pub trait ReadDir<T: DirEntry>: Iterator<Item = Result<T>> {}