renom/changes/
replace_in_file.rs1use std::{fmt::Display, path::PathBuf};
2
3use colored::Colorize;
4
5#[derive(Debug, PartialEq)]
6pub struct ReplaceInFile {
7 pub path: PathBuf,
8 pub from: String,
9 pub to: String,
10}
11
12impl ReplaceInFile {
13 pub fn new(path: impl Into<PathBuf>, from: impl Into<String>, to: impl Into<String>) -> Self {
14 Self {
15 path: path.into(),
16 from: from.into(),
17 to: to.into(),
18 }
19 }
20}
21
22impl Display for ReplaceInFile {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 write!(
25 f,
26 "replace {} with {} in file {}",
27 &self.from.dimmed(),
28 &self.to.dimmed(),
29 &self
30 .path
31 .to_str()
32 .unwrap_or("invalid Unicode path")
33 .dimmed()
34 )
35 }
36}