pub fn replace_all_in_file(
file_path: &Path,
search: &SearchType,
replace: &str,
) -> Result<bool>Expand description
Performs search and replace operations in a file
This function implements a hybrid approach to file replacements:
- For files under the
MAX_FILE_SIZEthreshold, it attempts an in-memory replacement - If the file is large or in-memory replacement fails, it falls back to line-by-line chunked replacement
This approach optimizes for performance while maintaining reasonable memory usage limits.
§Arguments
file_path- Path to the file to processsearch- The search pattern (fixed string, regex, or advanced regex)replace- The replacement string
§Returns
Ok(true)if replacements were made in the fileOk(false)if no replacements were made (no matches found)Errif any errors occurred during the operation