refactor: move new fns to their struct
This commit is contained in:
parent
17f6f877b6
commit
791fa74e78
3 changed files with 21 additions and 24 deletions
|
@ -1,20 +1,18 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
mod dir_item;
|
||||
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::*;
|
||||
use temp::TempFileSystem;
|
||||
pub use result::{Error, Result};
|
||||
|
||||
pub const fn new(base: PathBuf) -> FileSystem {
|
||||
real::new(base)
|
||||
pub const fn new(base: PathBuf) -> real::FileSystem {
|
||||
real::FileSystem::new(base)
|
||||
}
|
||||
|
||||
pub fn temp() -> Result<TempFileSystem> {
|
||||
temp::new()
|
||||
pub fn temp() -> Result<temp::TempFileSystem> {
|
||||
temp::TempFileSystem::new()
|
||||
}
|
||||
|
|
|
@ -7,15 +7,14 @@ use crate::fs::DirItem;
|
|||
|
||||
use super::{DirItemIterator, Result};
|
||||
|
||||
pub const fn new(base: PathBuf) -> FileSystem {
|
||||
FileSystem { base }
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FileSystem {
|
||||
base: PathBuf,
|
||||
}
|
||||
impl FileSystem {
|
||||
pub const fn new(base: PathBuf) -> Self {
|
||||
Self { base }
|
||||
}
|
||||
pub fn base(&self) -> &Path {
|
||||
&self.base
|
||||
}
|
||||
|
|
|
@ -4,24 +4,24 @@ use tempfile::TempDir;
|
|||
|
||||
use super::real::FileSystem;
|
||||
|
||||
pub(super) fn new() -> super::Result<TempFileSystem> {
|
||||
let temp_dir = tempfile::tempdir()?;
|
||||
let base = temp_dir.path().to_path_buf();
|
||||
let temp_dir = Arc::new(Mutex::new(temp_dir));
|
||||
let real = super::real::new(base);
|
||||
|
||||
Ok(TempFileSystem {
|
||||
real,
|
||||
_temp_dir: temp_dir,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TempFileSystem {
|
||||
real: FileSystem,
|
||||
_temp_dir: Arc<Mutex<TempDir>>,
|
||||
}
|
||||
impl TempFileSystem {
|
||||
pub fn new() -> super::Result<Self> {
|
||||
let temp_dir = tempfile::tempdir()?;
|
||||
let base = temp_dir.path().to_path_buf();
|
||||
let temp_dir = Arc::new(Mutex::new(temp_dir));
|
||||
let real = super::new(base);
|
||||
|
||||
Ok(Self {
|
||||
real,
|
||||
_temp_dir: temp_dir,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl std::ops::Deref for TempFileSystem {
|
||||
type Target = FileSystem;
|
||||
|
||||
|
|
Loading…
Reference in a new issue