fast-clean 1.1.2

A tool for quickly clean the target dir
Documentation
use std::cell::RefCell;
use std::io;
use std::path::{Path, PathBuf};

pub trait Remover {
    fn remove(&mut self, path: &Path) -> io::Result<()>;
}

/// 真正删除文件
#[allow(unused)]
pub struct RealRemover{
    pub(crate) is_skip_dir: bool,
}
impl Remover for RealRemover {
    fn remove(&mut self, path: &Path,) -> io::Result<()> {
        if path.is_file() {
            std::fs::remove_file(path)
        }else {
            if self.is_skip_dir {
                return Ok(())
            }
            std::fs::remove_dir_all(path)
        }
    }
}

/// MockRemover,用于测试
pub struct MockRemover {
    pub removed: RefCell<Vec<PathBuf>>,
}

impl MockRemover {
    pub fn new() -> Self {
        Self {
            removed: RefCell::new(Vec::new()),
        }
    }
}

impl Remover for MockRemover {
    fn remove(&mut self, path: &Path) -> io::Result<()> {
        self.removed.borrow_mut().push(path.to_path_buf());
        Ok(())
    }
}