#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct FileStat {
pub exists: bool,
pub size: u64,
}
#[derive(Debug, thiserror::Error)]
#[error("{0}")]
pub struct FsError(pub String);
impl FsError {
pub fn new(reason: impl Into<String>) -> Self {
Self(reason.into())
}
}
pub trait Filesystem {
fn write_atomic(&self, path: &str, bytes: &[u8]) -> Result<(), FsError>;
fn rename(&self, from: &str, to: &str) -> Result<(), FsError>;
fn remove(&self, path: &str) -> Result<(), FsError>;
fn prune_empty_dirs(&self, root: &str) -> Result<(), FsError>;
fn read(&self, path: &str) -> Result<Vec<u8>, FsError>;
fn metadata(&self, path: &str) -> Option<FileStat>;
}