chore: clippy

This commit is contained in:
sinavir 2024-05-22 12:39:31 +02:00
parent a98da9d47c
commit 435a85732c
3 changed files with 14 additions and 18 deletions

View file

@ -13,13 +13,10 @@ pub struct BridgeConfig {
pub mapping: BiMap<String, String>,
}
impl<'a> BridgeConfig {
pub fn load<'b>() -> Result<BridgeConfig, String> {
impl BridgeConfig {
pub fn load() -> Result<BridgeConfig, String> {
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: "__",

View file

@ -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

View file

@ -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<String>) {
pub fn attach(&mut self, attach: Vec<String>) {
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<String> {
async fn handle_attachment(&self, attachment: &Value) -> Option<String> {
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<String, Value>,
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}")))