refactor: extract result module
This commit is contained in:
parent
a629950d4d
commit
892899bfe2
2 changed files with 26 additions and 22 deletions
|
@ -1,35 +1,16 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use derive_more::From;
|
||||
|
||||
mod real;
|
||||
mod result;
|
||||
mod temp;
|
||||
|
||||
mod dir_item;
|
||||
|
||||
pub use dir_item::DirItem;
|
||||
pub use dir_item::DirItemIterator;
|
||||
use real::FileSystem;
|
||||
pub use result::{Result, Error};
|
||||
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 {
|
||||
real::new(base)
|
||||
}
|
||||
|
|
23
src/fs/result.rs
Normal file
23
src/fs/result.rs
Normal 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>;
|
Loading…
Reference in a new issue