refactor: extract result module
All checks were successful
Rust / build (map[name:nightly]) (push) Successful in 1m55s
Rust / build (map[name:stable]) (push) Successful in 2m5s
Release Please / Release-plz (push) Successful in 1m33s

This commit is contained in:
Paul Campbell 2024-11-01 08:32:33 +00:00
parent a629950d4d
commit b756881a60
2 changed files with 25 additions and 21 deletions

View file

@ -1,35 +1,16 @@
use std::path::PathBuf; use std::path::PathBuf;
use derive_more::From;
mod real; mod real;
mod result;
mod temp; mod temp;
mod dir_item; mod dir_item;
pub use dir_item::DirItem; pub use dir_item::DirItem;
pub use dir_item::DirItemIterator; pub use dir_item::DirItemIterator;
use real::FileSystem; use real::FileSystem;
pub use result::*;
use temp::TempFileSystem; use temp::TempFileSystem;
#[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,
},
#[display("Path must be a directory: {path:?}")]
NotADirectory {
path: PathBuf,
},
}
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;
pub const fn new(base: PathBuf) -> FileSystem { pub const fn new(base: PathBuf) -> FileSystem {
real::new(base) real::new(base)
} }

23
src/fs/result.rs Normal file
View file

@ -0,0 +1,23 @@
//
use std::path::PathBuf;
use derive_more::From;
#[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,
},
#[display("Path must be a directory: {path:?}")]
NotADirectory {
path: PathBuf,
},
}
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;