Mercurial > hg
comparison rust/hg-core/src/matchers.rs @ 43611:27c25c0dc967
rust-matchers: remove default implementations for `Matcher` trait
We don't expect a whole lot of matchers to be defined, and this makes it more
obvious what a matcher does by reading its `impl Matcher for FooMatcher`.
This patch has the added benefit of fixing the `AlwaysMatcher`, its `matches`
function differs from the former default.
Differential Revision: https://phab.mercurial-scm.org/D7255
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 06 Nov 2019 16:24:24 +0100 |
parents | a77d4fe347a4 |
children | 1bb4e9b02984 |
comparison
equal
deleted
inserted
replaced
43610:11db74349b24 | 43611:27c25c0dc967 |
---|---|
24 | 24 |
25 pub trait Matcher { | 25 pub trait Matcher { |
26 /// Explicitly listed files | 26 /// Explicitly listed files |
27 fn file_set(&self) -> HashSet<&HgPath>; | 27 fn file_set(&self) -> HashSet<&HgPath>; |
28 /// Returns whether `filename` is in `file_set` | 28 /// Returns whether `filename` is in `file_set` |
29 fn exact_match(&self, _filename: impl AsRef<HgPath>) -> bool { | 29 fn exact_match(&self, filename: impl AsRef<HgPath>) -> bool; |
30 false | |
31 } | |
32 /// Returns whether `filename` is matched by this matcher | 30 /// Returns whether `filename` is matched by this matcher |
33 fn matches(&self, _filename: impl AsRef<HgPath>) -> bool { | 31 fn matches(&self, filename: impl AsRef<HgPath>) -> bool; |
34 false | |
35 } | |
36 /// Decides whether a directory should be visited based on whether it | 32 /// Decides whether a directory should be visited based on whether it |
37 /// has potential matches in it or one of its subdirectories, and | 33 /// has potential matches in it or one of its subdirectories, and |
38 /// potentially lists which subdirectories of that directory should be | 34 /// potentially lists which subdirectories of that directory should be |
39 /// visited. This is based on the match's primary, included, and excluded | 35 /// visited. This is based on the match's primary, included, and excluded |
40 /// patterns. | 36 /// patterns. |
69 /// no files in this dir to investigate (or equivalently that if there are | 65 /// no files in this dir to investigate (or equivalently that if there are |
70 /// files to investigate in 'dir' that it will always return | 66 /// files to investigate in 'dir' that it will always return |
71 /// `VisitChildrenSet::This`). | 67 /// `VisitChildrenSet::This`). |
72 fn visit_children_set( | 68 fn visit_children_set( |
73 &self, | 69 &self, |
74 _directory: impl AsRef<HgPath>, | 70 directory: impl AsRef<HgPath>, |
75 ) -> VisitChildrenSet { | 71 ) -> VisitChildrenSet; |
76 VisitChildrenSet::This | |
77 } | |
78 /// Matcher will match everything and `files_set()` will be empty: | 72 /// Matcher will match everything and `files_set()` will be empty: |
79 /// optimization might be possible. | 73 /// optimization might be possible. |
80 fn matches_everything(&self) -> bool { | 74 fn matches_everything(&self) -> bool; |
81 false | |
82 } | |
83 /// Matcher will match exactly the files in `files_set()`: optimization | 75 /// Matcher will match exactly the files in `files_set()`: optimization |
84 /// might be possible. | 76 /// might be possible. |
85 fn is_exact(&self) -> bool { | 77 fn is_exact(&self) -> bool; |
86 false | |
87 } | |
88 } | 78 } |
89 | 79 |
90 /// Matches everything. | 80 /// Matches everything. |
91 #[derive(Debug)] | 81 #[derive(Debug)] |
92 pub struct AlwaysMatcher; | 82 pub struct AlwaysMatcher; |
93 | 83 |
94 impl Matcher for AlwaysMatcher { | 84 impl Matcher for AlwaysMatcher { |
95 fn file_set(&self) -> HashSet<&HgPath> { | 85 fn file_set(&self) -> HashSet<&HgPath> { |
96 HashSet::new() | 86 HashSet::new() |
97 } | 87 } |
98 | 88 fn exact_match(&self, _filename: impl AsRef<HgPath>) -> bool { |
89 false | |
90 } | |
91 fn matches(&self, _filename: impl AsRef<HgPath>) -> bool { | |
92 true | |
93 } | |
99 fn visit_children_set( | 94 fn visit_children_set( |
100 &self, | 95 &self, |
101 _directory: impl AsRef<HgPath>, | 96 _directory: impl AsRef<HgPath>, |
102 ) -> VisitChildrenSet { | 97 ) -> VisitChildrenSet { |
103 VisitChildrenSet::Recursive | 98 VisitChildrenSet::Recursive |
104 } | 99 } |
100 fn matches_everything(&self) -> bool { | |
101 true | |
102 } | |
103 fn is_exact(&self) -> bool { | |
104 false | |
105 } | |
105 } | 106 } |