Skip to content

Commit

Permalink
chore!: Make Replacement a newtype
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Nov 6, 2023
1 parent 9aa5a78 commit 59d6daf
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/actions/replace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ use unescape::unescape;
/// );
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Replacement {
replacement: String,
}
pub struct Replacement(String);

impl Replacement {
/// Creates a new replacement.
#[must_use]
pub fn new(replacement: String) -> Self {
Self { replacement }
Self(replacement)
}
}

Expand All @@ -61,11 +59,9 @@ impl TryFrom<String> for Replacement {

fn try_from(replacement: String) -> Result<Self, Self::Error> {
match unescape(&replacement) {
Some(res) => Ok(Self {
replacement: res.to_string(),
}),
Some(res) => Ok(Self(res)),
None => Err(ReplacementCreationError::InvalidEscapeSequences(
replacement.to_string(),
replacement,
)),
}
}
Expand All @@ -92,7 +88,7 @@ impl Error for ReplacementCreationError {}

impl Action for Replacement {
fn act(&self, input: &str) -> String {
info!("Substituting '{}' with '{}'", input, self.replacement);
self.replacement.clone()
info!("Substituting '{}' with '{}'", input, self.0);
self.0.clone()
}
}

0 comments on commit 59d6daf

Please sign in to comment.