kxio 1.1.2

Provides injectable Filesystem and Network resources to make code more testable
Documentation
use std::sync::{Arc, Mutex};

use tempfile::TempDir;

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: super::real::RealFileSystem,
    _temp_dir: Arc<Mutex<TempDir>>,
}

impl std::ops::Deref for TempFileSystem {
    type Target = dyn super::FileSystemLike;

    fn deref(&self) -> &Self::Target {
        &self.real
    }
}