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;
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()
}

View file

@ -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
}

View file

@ -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;