diff --git a/src/config.rs b/src/config.rs index 7b8c73e..3a80937 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,13 +13,10 @@ pub struct BridgeConfig { pub mapping: BiMap, } -impl<'a> BridgeConfig { - pub fn load<'b>() -> Result { +impl BridgeConfig { + pub fn load() -> Result { initialize(Args { - config_path: env::var("CONFIG_PATH") - .ok() - .as_ref() - .map(|p| Path::new(p).as_ref()), + config_path: env::var("CONFIG_PATH").ok().as_ref().map(Path::new), logging: Logging::StdOut, auto_map_env: Some(AutoMapEnvArgs { divider: "__", diff --git a/src/main.rs b/src/main.rs index de43c66..21bcd7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,6 @@ use serde_json::Value; use tokio::time::sleep; use core::time::Duration; use transform::Bridge; -use {log, pretty_env_logger}; use crate::jsonrpc::RpcClient; use crate::config::BridgeConfig; @@ -36,7 +35,7 @@ async fn main() -> Result<(), String> { .map_err(|e| format!("Error while initializing irc stream: {e}"))?; log::debug!("Initializing IRC"); - while client.list_channels().is_some_and(|x| x.len() == 0) { + while client.list_channels().is_some_and(|x| x.is_empty()) { stream .next() .await @@ -59,7 +58,7 @@ async fn main() -> Result<(), String> { } sleep(Duration::from_secs(1)).await; }; - return Err("Trying too many times to open socket"); + Err("Trying too many times to open socket") }).await.map_err(|e| format!("failed to connect to signal socket: {e}"))?; let signal_stream = signal_client diff --git a/src/transform.rs b/src/transform.rs index afee470..ab92a27 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -14,23 +14,23 @@ struct SignalMessageBuilder<'a> { } impl<'b> SignalMessageBuilder<'b> { - pub fn message(self: &mut Self, message: String) { + pub fn message(&mut self, message: String) { self.message = Some(message); } - pub fn from(self: &mut Self, from: String) { + pub fn from(&mut self, from: String) { self.from = Some(from); } - pub fn attach(self: &mut Self, attach: Vec) { + pub fn attach(&mut self, attach: Vec) { self.attachments_urls.extend_from_slice(&attach); } - pub fn target(self: &mut Self, channel: Option<&'b String>) { + pub fn target(&mut self, channel: Option<&'b String>) { self.target = channel; } - pub fn build(self: Self) -> Option<(&'b String, String)> + pub fn build(self) -> Option<(&'b String, String)> { let attachments_text = self.attachments_urls.join(", "); (match (&self.message, attachments_text.len()) { @@ -70,7 +70,7 @@ impl<'a> Bridge<'a> { } } - async fn handle_attachment(self: &Self, attachment: &Value) -> Option { + async fn handle_attachment(&self, attachment: &Value) -> Option { if let Value::Object(a) = attachment { if let Some(Value::String(fname)) = a.get("id") { match copy( @@ -94,7 +94,7 @@ impl<'a> Bridge<'a> { } async fn process_signal( - self: &Self, + &self, message: &Map, result: &mut SignalMessageBuilder<'a>, ) { @@ -119,7 +119,7 @@ impl<'a> Bridge<'a> { } } - pub async fn signal2irc(self: &Self, signal: Value) -> Option<(&String, String)> { + pub async fn signal2irc(&self, signal: Value) -> Option<(&String, String)> { let mut result: SignalMessageBuilder = SignalMessageBuilder::default(); if let Value::Object(map) = signal { if let Some(Value::Object(envelope)) = map.get("envelope") { @@ -139,7 +139,7 @@ impl<'a> Bridge<'a> { result.build() } - pub fn irc2signal(self: &Self, message: Message) -> Option<(&String, String)> { + pub fn irc2signal(&self, message: Message) -> Option<(&String, String)> { match (message.prefix, message.command) { (Some(Prefix::Nickname(from, _, _)), Command::PRIVMSG(channel, message)) => { Some((channel, format!("<{from}>: {message}")))