Function rood::sys::file::replace_all[][src]

pub fn replace_all<T>(p: T, pattern: &str, to: &str) -> Result<()> where
    T: AsRef<Path>, 

Replace all instances of a pattern in file.

Will read the file into memory, and will replace every instance of the provided pattern before writing back the buffer to the file.

Examples

use std::fs;
use rood::sys::file;
use std::io::Write;

let file_name = "myfile.txt";

// Create a file named "myfile.txt" and write some text to it.
fs::File::create(file_name).unwrap().write_all(b"Hello there world. Hello again.").unwrap();

// Use replace_all to replace all instances of "Hello" by "Goodbye".
file::replace_all(file_name, "Hello", "Goodbye").unwrap();

assert!(!fs::read_to_string(file_name).unwrap().contains("Hello"));