Skip to main content

replace_all_in_file

Function replace_all_in_file 

Source
pub fn replace_all_in_file(
    file_path: &Path,
    search: &SearchType,
    replace: &str,
    multiline: bool,
) -> Result<bool>
Expand description

Performs search and replace operations in a file

When multiline is enabled: reads the entire file into memory and performs replacements spanning multiple lines. When multiline is disabled: reads line-by-line and performs replacements within lines.

§Arguments

  • file_path - Path to the file to process
  • search - The search pattern (fixed string, regex, or advanced regex)
  • replace - The replacement string
  • multiline - Whether to enable multiline replacement (whole-text matching)

§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