use std::path::PathBuf; use derive_more::From; use crate::fs::like::FileSystemLike; mod like; mod real; mod temp; #[derive(Debug, From, derive_more::Display)] pub enum Error { Io(std::io::Error), #[display("Path access attempted outside of base ({base:?}): {path:?}")] PathTraversal { base: PathBuf, path: PathBuf, }, } pub type Result = core::result::Result; pub const fn new(base: PathBuf) -> FileSystem { FileSystem::Real(real::new(base)) } pub fn temp() -> Result { temp::new().map(FileSystem::Temp) } pub enum FileSystem { Real(real::RealFileSystem), Temp(temp::TempFileSystem), } impl std::ops::Deref for FileSystem { type Target = dyn FileSystemLike; fn deref(&self) -> &Self::Target { match self { Self::Real(fs) => fs, Self::Temp(fs) => fs.deref(), } } }