mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 18:57:02 +05:30
all: fix clippy::pedantic
lints
This commit is contained in:
parent
e7a5ed6982
commit
f217ca95a5
2 changed files with 12 additions and 10 deletions
|
@ -19,11 +19,11 @@ pub struct Substitutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Match {
|
pub trait Match {
|
||||||
fn check_match<'a>(self: Self, string: &'a str) -> bool;
|
fn check_match(self, string: &str) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Act {
|
pub trait Act {
|
||||||
fn apply_action(self: Self, input: String) -> String;
|
fn apply_action(self, input: String) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
@ -39,16 +39,16 @@ pub enum Matcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Match for Matcher {
|
impl Match for Matcher {
|
||||||
fn check_match<'a>(self: Self, string: &'a str) -> bool {
|
fn check_match(self, string: &str) -> bool {
|
||||||
return 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 } => {
|
||||||
let regex = Regex::from_str(&pattern).expect("Failed to parse regex");
|
let regex = Regex::from_str(&pattern).expect("Failed to parse regex");
|
||||||
regex.is_match(&string)
|
regex.is_match(string)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ pub enum Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Act for Action {
|
impl Act for Action {
|
||||||
fn apply_action(self: Self, input: String) -> String {
|
fn apply_action(self, input: String) -> 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),
|
||||||
|
|
|
@ -5,13 +5,13 @@ use std::ops::Not;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||||
use dirs::config_dir;
|
use dirs::config_dir;
|
||||||
use log::debug;
|
use log::{debug, error};
|
||||||
|
|
||||||
use crate::config::{Act, Match, Replacements};
|
use crate::config::{Act, Match, Replacements};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
let mut config_path = config_dir().ok_or(anyhow!("Failed to get config dir"))?;
|
let mut config_path = config_dir().ok_or_else(|| anyhow!("Failed to get config dir"))?;
|
||||||
config_path.push("substitutor");
|
config_path.push("substitutor");
|
||||||
config_path.push("config");
|
config_path.push("config");
|
||||||
config_path.set_extension("toml");
|
config_path.set_extension("toml");
|
||||||
|
@ -34,7 +34,9 @@ fn main() -> Result<()> {
|
||||||
debug!("{}: matched on {}...", &subst.name, truncate(&contents, 40));
|
debug!("{}: matched on {}...", &subst.name, truncate(&contents, 40));
|
||||||
}
|
}
|
||||||
let result = subst.action.clone().apply_action(contents);
|
let result = subst.action.clone().apply_action(contents);
|
||||||
let _ = clipboard.set_contents(result);
|
if let Err(e) = clipboard.set_contents(result) {
|
||||||
|
error!("{}", e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue