Function replace_all_in_file

Source
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:

  1. For files under the MAX_FILE_SIZE threshold, it attempts an in-memory replacement
  2. 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 process
  • search - The search pattern (fixed string, regex, or advanced regex)
  • replace - The replacement string

§Returns

  • Ok(true) if replacements were made in the file
  • Ok(false) if no replacements were made (no matches found)
  • Err if any errors occurred during the operation