mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 18:57:02 +05:30
refactor: don't move value in Act and Match implementations
This commit is contained in:
parent
28710ab3ed
commit
a112cbefc6
1 changed files with 9 additions and 9 deletions
|
@ -49,19 +49,19 @@ pub enum Action<'config> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Match {
|
pub trait Match {
|
||||||
fn check_match(self, string: &str) -> bool;
|
fn check_match(&self, string: &str) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Act {
|
pub trait Act {
|
||||||
fn apply_action(self, input: &str) -> String;
|
fn apply_action(&self, input: &str) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Match for Matcher<'_> {
|
impl Match for Matcher<'_> {
|
||||||
fn check_match(self, string: &str) -> bool {
|
fn check_match(&self, string: &str) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Matcher::StartsWith { prefix } => string.starts_with(&prefix),
|
Matcher::StartsWith { prefix } => string.starts_with(prefix),
|
||||||
Matcher::EndsWith { suffix } => string.ends_with(&suffix),
|
Matcher::EndsWith { suffix } => string.ends_with(suffix),
|
||||||
Matcher::Contains { substring } => string.contains(&substring),
|
Matcher::Contains { substring } => string.contains(substring),
|
||||||
Matcher::Regex { pattern } => {
|
Matcher::Regex { pattern } => {
|
||||||
return if let Ok(regex) = Regex::from_str(pattern) {
|
return if let Ok(regex) = Regex::from_str(pattern) {
|
||||||
regex.is_match(string)
|
regex.is_match(string)
|
||||||
|
@ -69,18 +69,18 @@ impl Match for Matcher<'_> {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Matcher::Exactly { content } => string == content,
|
Matcher::Exactly { content } => &string == content,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Act for Action<'_> {
|
impl Act for Action<'_> {
|
||||||
fn apply_action(self, input: &str) -> String {
|
fn apply_action(&self, input: &str) -> String {
|
||||||
return match self {
|
return match self {
|
||||||
Action::Replace { from, to } => input.replace(from, to),
|
Action::Replace { from, to } => input.replace(from, to),
|
||||||
Action::Prefix { prefix } => format!("{prefix}{input}"),
|
Action::Prefix { prefix } => format!("{prefix}{input}"),
|
||||||
Action::Suffix { suffix } => format!("{input}{suffix}"),
|
Action::Suffix { suffix } => format!("{input}{suffix}"),
|
||||||
Action::Set { content } => content.to_owned(),
|
Action::Set { content } => content.to_owned().to_owned(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue