refactor: move new fns to their struct
All checks were successful
Rust / build (map[name:stable]) (push) Successful in 2m12s
Rust / build (map[name:nightly]) (push) Successful in 4m22s
Release Please / Release-plz (push) Successful in 38s

This commit is contained in:
Paul Campbell 2024-11-01 18:52:11 +00:00
parent 17f6f877b6
commit 791fa74e78
3 changed files with 21 additions and 24 deletions

View file

@ -1,20 +1,18 @@
use std::path::PathBuf; use std::path::PathBuf;
mod dir_item;
mod real; mod real;
mod result; mod result;
mod temp; mod temp;
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; pub use result::{Error, Result};
pub use result::*;
use temp::TempFileSystem;
pub const fn new(base: PathBuf) -> FileSystem { pub const fn new(base: PathBuf) -> real::FileSystem {
real::new(base) real::FileSystem::new(base)
} }
pub fn temp() -> Result<TempFileSystem> { pub fn temp() -> Result<temp::TempFileSystem> {
temp::new() temp::TempFileSystem::new()
} }

View file

@ -7,15 +7,14 @@ use crate::fs::DirItem;
use super::{DirItemIterator, Result}; use super::{DirItemIterator, Result};
pub const fn new(base: PathBuf) -> FileSystem {
FileSystem { base }
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct FileSystem { pub struct FileSystem {
base: PathBuf, base: PathBuf,
} }
impl FileSystem { impl FileSystem {
pub const fn new(base: PathBuf) -> Self {
Self { base }
}
pub fn base(&self) -> &Path { pub fn base(&self) -> &Path {
&self.base &self.base
} }

View file

@ -4,24 +4,24 @@ use tempfile::TempDir;
use super::real::FileSystem; 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)] #[derive(Clone, Debug)]
pub struct TempFileSystem { pub struct TempFileSystem {
real: FileSystem, real: FileSystem,
_temp_dir: Arc<Mutex<TempDir>>, _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 { impl std::ops::Deref for TempFileSystem {
type Target = FileSystem; type Target = FileSystem;