diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 17402f4..b8991bb 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -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 { - temp::new() +pub fn temp() -> Result { + temp::TempFileSystem::new() } diff --git a/src/fs/real.rs b/src/fs/real.rs index ca8a920..710a2e1 100644 --- a/src/fs/real.rs +++ b/src/fs/real.rs @@ -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 } diff --git a/src/fs/temp.rs b/src/fs/temp.rs index eedd2b1..eb1f3db 100644 --- a/src/fs/temp.rs +++ b/src/fs/temp.rs @@ -4,24 +4,24 @@ use tempfile::TempDir; use super::real::FileSystem; -pub(super) fn new() -> super::Result { - 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>, } +impl TempFileSystem { + pub fn new() -> super::Result { + 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;