diff --git a/src/config.rs b/src/config.rs index bf7aeab..9906173 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,11 +19,11 @@ pub struct Substitutor { } pub trait Match { - fn check_match<'a>(self: Self, string: &'a str) -> bool; + fn check_match(self, string: &str) -> bool; } pub trait Act { - fn apply_action(self: Self, input: String) -> String; + fn apply_action(self, input: String) -> String; } #[derive(Clone, Debug, Deserialize)] @@ -39,16 +39,16 @@ pub enum Matcher { } impl Match for Matcher { - fn check_match<'a>(self: Self, string: &'a str) -> bool { - return match self { + fn check_match(self, string: &str) -> bool { + match self { Matcher::StartsWith { prefix } => string.starts_with(&prefix), Matcher::EndsWith { suffix } => string.ends_with(&suffix), Matcher::Contains { substring } => string.contains(&substring), Matcher::Regex { pattern } => { 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 { - fn apply_action(self: Self, input: String) -> String { + fn apply_action(self, input: String) -> String { return match self { Action::Replace { from, to } => input.replace(&from, &to), Action::Prefix { prefix } => format!("{}{}", prefix, input), diff --git a/src/main.rs b/src/main.rs index ae80271..87a7eb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,13 +5,13 @@ use std::ops::Not; use anyhow::{anyhow, Result}; use clipboard::{ClipboardContext, ClipboardProvider}; use dirs::config_dir; -use log::debug; +use log::{debug, error}; use crate::config::{Act, Match, Replacements}; fn main() -> Result<()> { 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("config"); config_path.set_extension("toml"); @@ -34,7 +34,9 @@ fn main() -> Result<()> { debug!("{}: matched on {}...", &subst.name, truncate(&contents, 40)); } let result = subst.action.clone().apply_action(contents); - let _ = clipboard.set_contents(result); + if let Err(e) = clipboard.set_contents(result) { + error!("{}", e); + } }; } }