Mercurial > hg
diff rust/hg-core/src/matchers.rs @ 47378:777c3d231913
rust: Make some file path parameters less generic
These are not widely used APIs that benefit from being maximally flexible,
taking an explicit `&Path` borrow is fine and simplifies their internals.
Differential Revision: https://phab.mercurial-scm.org/D10833
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 02 Jun 2021 18:14:44 +0200 |
parents | 75f785888a7b |
children | f6bb181c75f8 |
line wrap: on
line diff
--- a/rust/hg-core/src/matchers.rs Mon Apr 26 22:59:56 2021 +0200 +++ b/rust/hg-core/src/matchers.rs Wed Jun 02 18:14:44 2021 +0200 @@ -237,7 +237,7 @@ /// /// /// let ignore_patterns = /// vec![IgnorePattern::new(PatternSyntax::RootGlob, b"this*", Path::new(""))]; -/// let (matcher, _) = IncludeMatcher::new(ignore_patterns, "").unwrap(); +/// let (matcher, _) = IncludeMatcher::new(ignore_patterns, "".as_ref()).unwrap(); /// /// /// assert_eq!(matcher.matches(HgPath::new(b"testing")), false); /// assert_eq!(matcher.matches(HgPath::new(b"this should work")), true); @@ -479,7 +479,7 @@ /// should be matched. fn build_match<'a, 'b>( ignore_patterns: &'a [IgnorePattern], - root_dir: impl AsRef<Path>, + root_dir: &Path, ) -> PatternResult<( Vec<u8>, Box<dyn Fn(&HgPath) -> bool + 'b + Sync>, @@ -500,7 +500,7 @@ for SubInclude { prefix, root, path } in subincludes.into_iter() { let (match_fn, warnings) = - get_ignore_function(vec![path.to_path_buf()], root)?; + get_ignore_function(vec![path.to_path_buf()], &root)?; all_warnings.extend(warnings); prefixes.push(prefix.to_owned()); submatchers.insert(prefix.to_owned(), match_fn); @@ -573,7 +573,7 @@ /// ignored. pub fn get_ignore_function<'a>( all_pattern_files: Vec<PathBuf>, - root_dir: impl AsRef<Path>, + root_dir: &Path, ) -> PatternResult<( Box<dyn for<'r> Fn(&'r HgPath) -> bool + Sync + 'a>, Vec<PatternFileWarning>, @@ -581,9 +581,9 @@ let mut all_patterns = vec![]; let mut all_warnings = vec![]; - for pattern_file in all_pattern_files.into_iter() { + for pattern_file in &all_pattern_files { let (patterns, warnings) = - get_patterns_from_file(pattern_file, &root_dir)?; + get_patterns_from_file(pattern_file, root_dir)?; all_patterns.extend(patterns.to_owned()); all_warnings.extend(warnings); @@ -599,7 +599,7 @@ impl<'a> IncludeMatcher<'a> { pub fn new( ignore_patterns: Vec<IgnorePattern>, - root_dir: impl AsRef<Path>, + root_dir: &Path, ) -> PatternResult<(Self, Vec<PatternFileWarning>)> { let (patterns, match_fn, warnings) = build_match(&ignore_patterns, root_dir)?; @@ -816,7 +816,7 @@ b"dir/subdir", Path::new(""), )], - "", + "".as_ref(), ) .unwrap(); @@ -854,7 +854,7 @@ b"dir/subdir", Path::new(""), )], - "", + "".as_ref(), ) .unwrap(); @@ -892,7 +892,7 @@ b"dir/z*", Path::new(""), )], - "", + "".as_ref(), ) .unwrap();