rust/hg-core/src/matchers.rs
changeset 49486 e8481625c582
parent 49478 d8ce883ff1f4
child 49558 363923bd51cd
equal deleted inserted replaced
49485:ffd4b1f1c9cb 49486:e8481625c582
    44     Set(HashSet<HgPathBuf>),
    44     Set(HashSet<HgPathBuf>),
    45     /// Visit this directory and all subdirectories
    45     /// Visit this directory and all subdirectories
    46     Recursive,
    46     Recursive,
    47 }
    47 }
    48 
    48 
    49 pub trait Matcher {
    49 pub trait Matcher: core::fmt::Debug {
    50     /// Explicitly listed files
    50     /// Explicitly listed files
    51     fn file_set(&self) -> Option<&HashSet<HgPathBuf>>;
    51     fn file_set(&self) -> Option<&HashSet<HgPathBuf>>;
    52     /// Returns whether `filename` is in `file_set`
    52     /// Returns whether `filename` is in `file_set`
    53     fn exact_match(&self, filename: &HgPath) -> bool;
    53     fn exact_match(&self, filename: &HgPath) -> bool;
    54     /// Returns whether `filename` is matched by this matcher
    54     /// Returns whether `filename` is matched by this matcher
   281     roots: HashSet<HgPathBuf>,
   281     roots: HashSet<HgPathBuf>,
   282     dirs: HashSet<HgPathBuf>,
   282     dirs: HashSet<HgPathBuf>,
   283     parents: HashSet<HgPathBuf>,
   283     parents: HashSet<HgPathBuf>,
   284 }
   284 }
   285 
   285 
       
   286 impl core::fmt::Debug for IncludeMatcher<'_> {
       
   287     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
       
   288         f.debug_struct("IncludeMatcher")
       
   289             .field("patterns", &String::from_utf8_lossy(&self.patterns))
       
   290             .field("prefix", &self.prefix)
       
   291             .field("roots", &self.roots)
       
   292             .field("dirs", &self.dirs)
       
   293             .field("parents", &self.parents)
       
   294             .finish()
       
   295     }
       
   296 }
       
   297 
   286 impl<'a> Matcher for IncludeMatcher<'a> {
   298 impl<'a> Matcher for IncludeMatcher<'a> {
   287     fn file_set(&self) -> Option<&HashSet<HgPathBuf>> {
   299     fn file_set(&self) -> Option<&HashSet<HgPathBuf>> {
   288         None
   300         None
   289     }
   301     }
   290 
   302 
   328         false
   340         false
   329     }
   341     }
   330 }
   342 }
   331 
   343 
   332 /// The union of multiple matchers. Will match if any of the matchers match.
   344 /// The union of multiple matchers. Will match if any of the matchers match.
       
   345 #[derive(Debug)]
   333 pub struct UnionMatcher {
   346 pub struct UnionMatcher {
   334     matchers: Vec<Box<dyn Matcher + Sync>>,
   347     matchers: Vec<Box<dyn Matcher + Sync>>,
   335 }
   348 }
   336 
   349 
   337 impl Matcher for UnionMatcher {
   350 impl Matcher for UnionMatcher {
   391     pub fn new(matchers: Vec<Box<dyn Matcher + Sync>>) -> Self {
   404     pub fn new(matchers: Vec<Box<dyn Matcher + Sync>>) -> Self {
   392         Self { matchers }
   405         Self { matchers }
   393     }
   406     }
   394 }
   407 }
   395 
   408 
       
   409 #[derive(Debug)]
   396 pub struct IntersectionMatcher {
   410 pub struct IntersectionMatcher {
   397     m1: Box<dyn Matcher + Sync>,
   411     m1: Box<dyn Matcher + Sync>,
   398     m2: Box<dyn Matcher + Sync>,
   412     m2: Box<dyn Matcher + Sync>,
   399     files: Option<HashSet<HgPathBuf>>,
   413     files: Option<HashSet<HgPathBuf>>,
   400 }
   414 }
   472         };
   486         };
   473         Self { m1, m2, files }
   487         Self { m1, m2, files }
   474     }
   488     }
   475 }
   489 }
   476 
   490 
       
   491 #[derive(Debug)]
   477 pub struct DifferenceMatcher {
   492 pub struct DifferenceMatcher {
   478     base: Box<dyn Matcher + Sync>,
   493     base: Box<dyn Matcher + Sync>,
   479     excluded: Box<dyn Matcher + Sync>,
   494     excluded: Box<dyn Matcher + Sync>,
   480     files: Option<HashSet<HgPathBuf>>,
   495     files: Option<HashSet<HgPathBuf>>,
   481 }
   496 }