MCPcopy Create free account
hub / github.com/Nariod/RustPacker / search_and_replace

Function search_and_replace

src/puzzle.rs:33–48  ·  view source on GitHub ↗
(
    path_to_file: &Path,
    search: &str,
    replace: &str,
)

Source from the content-addressed store, hash-verified

31const OUTPUT_DIR: &str = "shared";
32
33fn search_and_replace(
34 path_to_file: &Path,
35 search: &str,
36 replace: &str,
37) -> Result<(), Box<dyn std::error::Error>> {
38 let file_content = fs::read_to_string(path_to_file)?;
39 let new_content = file_content.replace(search, replace);
40
41 let mut file = OpenOptions::new()
42 .write(true)
43 .truncate(true)
44 .open(path_to_file)?;
45 file.write_all(new_content.as_bytes())?;
46
47 Ok(())
48}
49
50fn create_root_folder(parent: &Path) -> Result<PathBuf, Box<dyn std::error::Error>> {
51 let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();

Callers 1

apply_replacementsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected