rs-dot-ignore 0.1.0

A Rust library and CLI utility for **efficient directory walking with `.ignore`-style file exclusion** — inspired by `.gitignore` behavior.
Documentation
use globset::{Glob, GlobSet, GlobSetBuilder};
use std::{collections::HashSet, path::PathBuf};

/// IgnoreSet
/// 
/// `GlobSet` dosn't have any feature to add item.
/// As we are making scope for each .ignore file,
/// thats why we have to made this struct.
/// 
/// This is a combination of `GlobSet` and `HashSet`
/// Where we can insert, replace, build whenever needed.
/// 
#[derive(Clone)]
pub struct IgnoreSet {
    pub dir: PathBuf,
    hashset: HashSet<String>,
    globset: GlobSet,
}

impl IgnoreSet {
    /// New Instance of IgnoreSet
    /// 
    pub fn new(dir: &PathBuf) -> Self {
        Self {
            dir: dir.clone(),
            hashset: HashSet::new(),
            globset: GlobSet::empty(),
        }
    }

    /// Insert
    /// 
    /// Inset item to the set
    pub fn insert(&mut self, value: &str) {
        self.hashset.insert(value.to_string());
    }

    /// Replace
    /// 
    /// Replace the wholeset.
    pub fn replace(&mut self, ignoreset: IgnoreSet) {
        self.hashset = ignoreset.hashset;
        self.globset = ignoreset.globset;
    }

    /// Compile
    /// 
    /// Making the set ready for matching.
    pub fn compile(&mut self) {
        let mut globset_builder = GlobSetBuilder::new();

        self.hashset.iter().for_each(|item| {
            globset_builder.add(Glob::new(item).unwrap());
        });

        self.globset = globset_builder.build().unwrap();
    }

    /// is_matched
    /// 
    /// Matches value with set.
    /// 
    /// Note: must `self.compile()` the set before calling this function.
    pub fn is_matched(&self, value: &str) -> bool {
        self.globset.is_match(value)
    }
}