Patchwork D7525: rust-matchers: improve `Matcher` trait ergonomics

login
register
mail settings
Submitter phabricator
Date Dec. 10, 2019, 4:18 p.m.
Message ID <b0dc57731e3ea1c0c12a39a0e7827a28@localhost.localdomain>
Download mbox | patch
Permalink /patch/43684/
State Not Applicable
Headers show

Comments

phabricator - Dec. 10, 2019, 4:18 p.m.
Closed by commit rHG1bb4e9b02984: rust-matchers: improve `Matcher` trait ergonomics (authored by Alphare).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7525?vs=18401&id=18583

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7525/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7525

AFFECTED FILES
  rust/hg-core/src/matchers.rs

CHANGE DETAILS




To: Alphare, #hg-reviewers, kevincox, pulkit
Cc: durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-core/src/matchers.rs b/rust/hg-core/src/matchers.rs
--- a/rust/hg-core/src/matchers.rs
+++ b/rust/hg-core/src/matchers.rs
@@ -10,21 +10,21 @@ 
 use crate::utils::hg_path::{HgPath, HgPathBuf};
 use std::collections::HashSet;
 
-pub enum VisitChildrenSet {
+pub enum VisitChildrenSet<'a> {
     /// Don't visit anything
     Empty,
     /// Only visit this directory
     This,
     /// Visit this directory and these subdirectories
     /// TODO Should we implement a `NonEmptyHashSet`?
-    Set(HashSet<HgPathBuf>),
+    Set(HashSet<&'a HgPath>),
     /// Visit this directory and all subdirectories
     Recursive,
 }
 
 pub trait Matcher {
     /// Explicitly listed files
-    fn file_set(&self) -> HashSet<&HgPath>;
+    fn file_set(&self) -> Option<&HashSet<&HgPath>>;
     /// Returns whether `filename` is in `file_set`
     fn exact_match(&self, filename: impl AsRef<HgPath>) -> bool;
     /// Returns whether `filename` is matched by this matcher
@@ -82,8 +82,8 @@ 
 pub struct AlwaysMatcher;
 
 impl Matcher for AlwaysMatcher {
-    fn file_set(&self) -> HashSet<&HgPath> {
-        HashSet::new()
+    fn file_set(&self) -> Option<&HashSet<&HgPath>> {
+        None
     }
     fn exact_match(&self, _filename: impl AsRef<HgPath>) -> bool {
         false