From 2863fe52c1c354369fbb138617a01f69fda6d236 Mon Sep 17 00:00:00 2001 From: eternal-flame-AD Date: Thu, 5 Sep 2024 00:34:13 -0500 Subject: [PATCH] Clippy suggestions Signed-off-by: eternal-flame-AD --- src/client.rs | 42 +++++++++++++++++++++++++----------------- src/e2e.rs | 5 +++-- src/filter.rs | 3 ++- src/io.rs | 1 + src/lib.rs | 13 +++++++++++-- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/client.rs b/src/client.rs index ca3b5ab..0db1379 100644 --- a/src/client.rs +++ b/src/client.rs @@ -46,14 +46,17 @@ pub enum AuthMethod<'a> { } impl MatrixClient { + #[must_use] pub fn new(client: Client) -> Self { Self { client } } + #[must_use] pub fn new_arc(client: Client) -> Arc { Arc::new(Self::new(client)) } + #[must_use] pub fn client(&self) -> &Client { &self.client } @@ -65,9 +68,9 @@ impl MatrixClient { password, initial_device_display_name, } => { - let tmp = self.client.matrix_auth().login_username(user, &password); + let tmp = self.client.matrix_auth().login_username(user, password); if let Some(name) = initial_device_display_name { - tmp.initial_device_display_name(&name) + tmp.initial_device_display_name(name) } else { tmp } @@ -122,6 +125,7 @@ impl MatrixClient { } }; } + #[allow(clippy::match_wildcard_for_single_variants)] match msg { RoomMessageEvent::Original(msg) => { impl_file_like!(&msg.content.msgtype, Image, Video, Audio, File) @@ -130,6 +134,7 @@ impl MatrixClient { } } + #[allow(clippy::too_many_lines)] pub async fn setup_e2e(self: Arc) -> bool { let client = &self.client; @@ -242,20 +247,20 @@ impl MatrixClient { match verification { Verification::SasV1(v) => { v.accept().await.expect("Failed to accept verification"); - let emoji_str = v - .emoji() - .map(|emojis| { + let emoji_str = v.emoji().map_or_else( + || "No emojis".to_string(), + |emojis| { emojis .iter() .map(|e| format!("{} ({})", e.symbol, e.description)) .collect::>() .join(", ") - }) - .unwrap_or_else(|| "No emojis".to_string()); - let decimals = v - .decimals() - .map(|(n1, n2, n3)| format!("{} {} {}", n1, n2, n3)) - .unwrap_or_else(|| "No decimals".to_string()); + }, + ); + let decimals = v.decimals().map_or_else( + || "No decimals".to_string(), + |(n1, n2, n3)| format!("[{n1}, {n2}, {n3}]"), + ); if prompt( &mut stdin, @@ -330,12 +335,14 @@ impl MatrixClient { println!( "Verification for {}:\nEmoji: {}\nDecimals: [{}, {}, {}]\n Confirm? (y/n)", device.device_id(), - emojis.map(|e| e.emojis - .iter() - .map(|e| format!("{} ({})", e.symbol, e.description)) - .collect::>() - .join(", "), - ).unwrap_or_else(|| "No emojis".to_string()), + emojis.map_or_else( + || "No emojis".to_string(), + |e| e.emojis + .iter() + .map(|e| format!("{} ({})", e.symbol, e.description)) + .collect::>() + .join(", "), + ), decimals.0, decimals.1, decimals.2 ); @@ -385,6 +392,7 @@ impl MatrixClient { false } + #[allow(clippy::must_use_candidate)] pub fn room_messages( room: &Room, since: Option, diff --git a/src/e2e.rs b/src/e2e.rs index b83a69b..7789261 100644 --- a/src/e2e.rs +++ b/src/e2e.rs @@ -36,7 +36,7 @@ pub enum DecryptError { VersionMismatch, } -pub async fn try_decrypt<'s, E>( +pub fn try_decrypt<'s, E>( jwk: &JsonWebKey, data: impl TryStream, Error = E> + Send + 's, iv: &[u8], @@ -64,6 +64,7 @@ pub struct VerifyingStream<'a, S> { } impl<'a, S> VerifyingStream<'a, S> { + #[must_use] pub fn new(inner: Pin>, expected: &'a [u8]) -> Self { Self { inner, @@ -120,5 +121,5 @@ pub async fn decrypt_file<'s, E: std::error::Error + 's>( sha256_expect, )); - try_decrypt(&file.key, data, iv).await + try_decrypt(&file.key, data, iv) } diff --git a/src/filter.rs b/src/filter.rs index 878ddbc..d999943 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -3,6 +3,7 @@ use ruma_client_api::{ sync::sync_events::v3::Filter, }; +#[must_use] pub fn minimal_sync_filter() -> Filter { let mut filter = FilterDefinition::empty(); @@ -19,7 +20,7 @@ pub fn minimal_sync_filter() -> Filter { "m.room.avatar", ] .into_iter() - .map(|s| s.to_string()) + .map(ToString::to_string) .collect(), ); room_filter.timeline = room_event_filter; diff --git a/src/io.rs b/src/io.rs index 3747242..4373269 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,3 +1,4 @@ +#[must_use] pub fn sanitize_filename(name: &str) -> String { name.chars() .map(|c| match c { diff --git a/src/lib.rs b/src/lib.rs index cf21f5c..0f1ee31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,8 @@ +#![warn(clippy::pedantic)] +#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)] +#![allow(clippy::ignored_unit_patterns)] +#![allow(clippy::module_name_repetitions)] + use std::{ fs::OpenOptions, os::unix::fs::OpenOptionsExt, @@ -75,6 +80,7 @@ pub struct Args { pub key_sync_timeout: u64, } +#[must_use] pub fn mxc_url_to_https(mxc_url: &str, homeserver: &str) -> String { format!( "{}_matrix/media/r0/download/{}", @@ -113,6 +119,7 @@ pub enum DumpError { InvalidId(#[from] IdParseError), } +#[allow(clippy::too_many_lines)] pub async fn dump_room_messages( room: &matrix_sdk::Room, out_dir: &Path, @@ -135,7 +142,7 @@ pub async fn dump_room_messages( let mut out = Vec::with_capacity(msg.len()); - for event in msg.into_iter() { + for event in msg { let mut fm = None; match event.event.clone().cast::().deserialize() { Ok(event) => { @@ -235,6 +242,7 @@ pub async fn dump_room_messages( Ok(()) } +#[allow(clippy::too_many_lines)] pub async fn run( js: &mut JoinSet>, bg_js: &mut JoinSet>, @@ -352,6 +360,7 @@ pub async fn run( { log::info!("Starting E2E setup"); + #[allow(clippy::match_bool, clippy::single_match_else)] match client.clone().setup_e2e().await { true => log::info!("E2E setup done"), false => log::error!("E2E setup failed, E2E will not be decrypted"), @@ -426,7 +435,7 @@ pub async fn run( .unwrap_or(room.name().unwrap_or("unknown".to_string())); let room_dir = - Path::new(&out_dir).join(sanitize_filename(&format!("{}_{}", room_id, room_name))); + Path::new(&out_dir).join(sanitize_filename(&format!("{room_id}_{room_name}"))); let match_filter = if filter.is_empty() { true