From a0ba1db28ac5e7cd1dd3e95612e4965d1ed360be Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 24 Jan 2023 17:15:51 +0000 Subject: [PATCH] fix: adjust for toml 0.6.0 upgrade --- src/clipboard.rs | 8 +++---- src/config.rs | 59 +++++++++++++++++++++++------------------------- src/main.rs | 2 +- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/clipboard.rs b/src/clipboard.rs index 7435ffb..290f0eb 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -7,12 +7,12 @@ use tracing::{debug, error}; use crate::config::{Act, Match, Replacements}; -struct Handler<'a> { +struct Handler { ctx: ClipboardContext, - config: Replacements<'a>, + config: Replacements, } -impl<'a> ClipboardHandler for Handler<'a> { +impl ClipboardHandler for Handler { fn on_clipboard_change(&mut self) -> CallbackResult { if let Ok(contents) = self.ctx.get_contents() { if let Some(subst) = self @@ -39,7 +39,7 @@ impl<'a> ClipboardHandler for Handler<'a> { } } -pub fn monitor(config: Replacements<'_>) { +pub fn monitor(config: Replacements) { let ctx = ClipboardContext::new().expect("Failed to acquire clipboard"); let handler = Handler { ctx, config }; let _master = Master::new(handler).run(); diff --git a/src/config.rs b/src/config.rs index 49f52d6..ff81a65 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,57 +6,54 @@ use serde_derive::Deserialize; use tracing::trace; #[derive(Debug, Deserialize)] -pub struct Replacements<'config> { - #[serde(rename = "substitutor", borrow, default)] - pub substitutors: Vec>, +pub struct Replacements { + #[serde(rename = "substitutor", default)] + pub substitutors: Vec, } #[derive(Debug, Deserialize)] -pub struct Substitutor<'config> { +pub struct Substitutor { #[serde(default)] - pub name: &'config str, - #[serde(borrow, alias = "matcher")] - pub matcher: MatcherType<'config>, - #[serde(borrow)] - pub action: Action<'config>, + pub name: String, + #[serde(alias = "matcher")] + pub matcher: MatcherType, + pub action: Action, } #[derive(Debug, Deserialize)] #[serde(untagged)] -pub enum MatcherType<'config> { - #[serde(borrow)] - Single(Matcher<'config>), - #[serde(borrow)] - Multiple(Vec>), +pub enum MatcherType { + Single(Matcher), + Multiple(Vec), } #[derive(Debug, Deserialize)] -pub enum Matcher<'config> { +pub enum Matcher { #[serde(rename = "starts_with")] - StartsWith { prefix: &'config str }, + StartsWith { prefix: String }, #[serde(rename = "ends_with")] - EndsWith { suffix: &'config str }, + EndsWith { suffix: String }, #[serde(rename = "contains")] - Contains { substring: &'config str }, + Contains { substring: String }, #[serde(rename = "regex")] - Regex { pattern: &'config str }, + Regex { pattern: String }, #[serde(rename = "exactly")] - Exactly { content: &'config str }, + Exactly { content: String }, } #[derive(Debug, Deserialize)] -pub enum Action<'config> { +pub enum Action { #[serde(rename = "set")] - Set { content: &'config str }, + Set { content: String }, #[serde(rename = "replace")] Replace { - from: &'config str, - to: &'config str, + from: String, + to: String, }, #[serde(rename = "prefix")] - Prefix { prefix: &'config str }, + Prefix { prefix: String }, #[serde(rename = "suffix")] - Suffix { suffix: &'config str }, + Suffix { suffix: String }, } pub trait Match { @@ -67,7 +64,7 @@ pub trait Act { fn apply_action(&self, input: &str) -> String; } -impl Replacements<'_> { +impl Replacements { pub fn validate(&self) -> Result<()> { for subst in &self.substitutors { match &subst.matcher { @@ -93,7 +90,7 @@ impl Replacements<'_> { } } -impl Match for Matcher<'_> { +impl Match for Matcher { fn check_match(&self, string: &str) -> bool { trace!(?self, ?string, "Checking for match"); match self { @@ -112,7 +109,7 @@ impl Match for Matcher<'_> { } } -impl Match for MatcherType<'_> { +impl Match for MatcherType { fn check_match(&self, string: &str) -> bool { match self { MatcherType::Single(matcher) => matcher.check_match(string), @@ -123,14 +120,14 @@ impl Match for MatcherType<'_> { } } -impl Act for Action<'_> { +impl Act for Action { fn apply_action(&self, input: &str) -> String { trace!(?self, ?input, "Applying action"); match self { Action::Replace { from, to } => input.replace(from, to), Action::Prefix { prefix } => format!("{}{}", prefix, input), Action::Suffix { suffix } => format!("{}{}", input, suffix), - Action::Set { content } => content.to_owned().to_owned(), + Action::Set { content } => content.to_owned(), } } } diff --git a/src/main.rs b/src/main.rs index d705a6c..2d77343 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ fn main() -> Result<()> { let config_path = get_config_path()?; let config_str = std::fs::read_to_string(config_path.as_path()).unwrap_or_default(); - let config: Replacements<'_> = toml::from_str(&config_str)?; + let config: Replacements = toml::from_str(&config_str)?; config.validate()?; monitor(config); Ok(())