replace a pattern to a str in a file.
(file: &Path, pat: &str, to: &str)
| 1524 | |
| 1525 | /// replace a pattern to a str in a file. |
| 1526 | pub fn replace_string_in_file(file: &Path, pat: &str, to: &str) -> eyre::Result<()> { |
| 1527 | let content = std::fs::read_to_string(file)?; |
| 1528 | let content = content.replace(pat, to); |
| 1529 | std::fs::write(file, content)?; |
| 1530 | Ok(()) |
| 1531 | } |
| 1532 | |
| 1533 | pub fn relace_pattern_in_content(content: &str, pat: &str, to: &str) -> eyre::Result<String> { |
| 1534 | let pattern = format!(r"\b{pat}\b"); |
no outgoing calls
no test coverage detected