(
path: P,
pattern: &str,
limit: usize,
)
| 59 | } |
| 60 | |
| 61 | pub fn search_with_limit<P: AsRef<Path>>( |
| 62 | path: P, |
| 63 | pattern: &str, |
| 64 | limit: usize, |
| 65 | ) -> Result<Vec<MatchResult>, Box<dyn std::error::Error>> { |
| 66 | let regex = regex::Regex::new(pattern)?; |
| 67 | let path = path.as_ref(); |
| 68 | let mut matches = Vec::new(); |
| 69 | |
| 70 | if path.is_file() { |
| 71 | search_file(path, ®ex, &mut matches, limit)?; |
| 72 | } else if path.is_dir() { |
| 73 | let files = Self::files(path, FileSearchOptions::default())?; |
| 74 | for file in files { |
| 75 | if matches.len() >= limit { |
| 76 | break; |
| 77 | } |
| 78 | let _ = search_file(&file, ®ex, &mut matches, limit); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | Ok(matches) |
| 83 | } |
| 84 | |
| 85 | pub fn files<P: AsRef<Path>>( |
| 86 | path: P, |
nothing calls this directly
no test coverage detected