pub struct FileSearcher { /* private fields */ }Implementations§
Source§impl FileSearcher
impl FileSearcher
Source§impl FileSearcher
impl FileSearcher
pub fn new( search_config: ParsedSearchConfig, dir_config: ParsedDirConfig, ) -> Self
Sourcepub fn walk_files<F>(&self, cancelled: Option<&AtomicBool>, file_handler: F)
pub fn walk_files<F>(&self, cancelled: Option<&AtomicBool>, file_handler: F)
Walks through files in the configured directory and processes matches.
This method traverses the filesystem starting from the root_dir specified in the FileSearcher,
respecting the configured overrides (include/exclude patterns) and hidden file settings.
It uses parallel processing when possible for better performance.
§Parameters
-
cancelled- An optional atomic boolean that can be used to signal cancellation from another thread. If this is set totrueduring execution, the search will stop as soon as possible. -
file_handler- A closure that returns aFileVisitor. The returnedFileVisitoris a function that processes search results for each file with matches.
§Example
use std::{
sync::{atomic::AtomicBool, mpsc},
path::PathBuf,
};
use regex::Regex;
use ignore::{WalkState, overrides::Override};
use scooter_core::search::{FileSearcher, ParsedSearchConfig, ParsedDirConfig, SearchResult, SearchType};
let search_config = ParsedSearchConfig {
search: SearchType::Pattern(Regex::new("pattern").unwrap()),
replace: "replacement".to_string(),
multiline: false,
};
let dir_config = ParsedDirConfig {
overrides: Override::empty(),
root_dir: PathBuf::from("."),
include_hidden: false,
};
let searcher = FileSearcher::new(search_config, dir_config);
let cancelled = AtomicBool::new(false);
searcher.walk_files(Some(&cancelled), move || {
Box::new(move |results| {
if process(results).is_err() {
WalkState::Quit
} else {
WalkState::Continue
}
})
});
fn process(results: Vec<SearchResult>) -> anyhow::Result<()> {
println!("{results:?}");
Ok(())
}Sourcepub fn walk_files_and_replace(&self, cancelled: Option<&AtomicBool>) -> usize
pub fn walk_files_and_replace(&self, cancelled: Option<&AtomicBool>) -> usize
Walks through files in the configured directory and replaces matches.
This method traverses the filesystem starting from the root_dir specified in the FileSearcher,
respecting the configured overrides (include/exclude patterns) and hidden file settings.
It replaces all matches of the search pattern with the replacement text in each file.
§Parameters
cancelled- An optional atomic boolean that can be used to signal cancellation from another thread. If this is set totrueduring execution, the search will stop as soon as possible.
§Returns
The number of files that had replacements performed in them.
Trait Implementations§
Source§impl Clone for FileSearcher
impl Clone for FileSearcher
Source§fn clone(&self) -> FileSearcher
fn clone(&self) -> FileSearcher
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FileSearcher
impl RefUnwindSafe for FileSearcher
impl Send for FileSearcher
impl Sync for FileSearcher
impl Unpin for FileSearcher
impl UnsafeUnpin for FileSearcher
impl UnwindSafe for FileSearcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more