use std::{
io::{self, Error, ErrorKind},
path::Path,
};
pub trait Fs: std::fmt::Debug {
fn is_dir(&self, path: &Path) -> bool;
fn is_file(&self, path: &Path) -> bool;
fn read(&self, path: &Path) -> io::Result<Vec<u8>>;
}
#[derive(Debug)]
pub struct StdFs;
impl Fs for StdFs {
#[inline]
fn is_file(&self, path: &Path) -> bool {
path.is_file()
}
#[inline]
fn is_dir(&self, path: &Path) -> bool {
path.is_dir()
}
#[inline]
fn read(&self, path: &Path) -> io::Result<Vec<u8>> {
std::fs::read(path)
}
}
#[derive(Debug)]
pub struct NullFs;
impl Fs for NullFs {
#[inline]
fn is_file(&self, _path: &Path) -> bool {
false
}
#[inline]
fn is_dir(&self, _path: &Path) -> bool {
false
}
#[inline]
fn read(&self, _path: &Path) -> io::Result<Vec<u8>> {
Err(Error::new(
ErrorKind::NotFound,
"NullFs, there is no file system",
))
}
}