Clippy suggestions

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
ゆめ 2024-09-05 00:34:13 -05:00
parent f0f7542332
commit 2863fe52c1
No known key found for this signature in database
5 changed files with 42 additions and 22 deletions

View file

@ -46,14 +46,17 @@ pub enum AuthMethod<'a> {
} }
impl MatrixClient { impl MatrixClient {
#[must_use]
pub fn new(client: Client) -> Self { pub fn new(client: Client) -> Self {
Self { client } Self { client }
} }
#[must_use]
pub fn new_arc(client: Client) -> Arc<Self> { pub fn new_arc(client: Client) -> Arc<Self> {
Arc::new(Self::new(client)) Arc::new(Self::new(client))
} }
#[must_use]
pub fn client(&self) -> &Client { pub fn client(&self) -> &Client {
&self.client &self.client
} }
@ -65,9 +68,9 @@ impl MatrixClient {
password, password,
initial_device_display_name, 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 { if let Some(name) = initial_device_display_name {
tmp.initial_device_display_name(&name) tmp.initial_device_display_name(name)
} else { } else {
tmp tmp
} }
@ -122,6 +125,7 @@ impl MatrixClient {
} }
}; };
} }
#[allow(clippy::match_wildcard_for_single_variants)]
match msg { match msg {
RoomMessageEvent::Original(msg) => { RoomMessageEvent::Original(msg) => {
impl_file_like!(&msg.content.msgtype, Image, Video, Audio, File) 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<Self>) -> bool { pub async fn setup_e2e(self: Arc<Self>) -> bool {
let client = &self.client; let client = &self.client;
@ -242,20 +247,20 @@ impl MatrixClient {
match verification { match verification {
Verification::SasV1(v) => { Verification::SasV1(v) => {
v.accept().await.expect("Failed to accept verification"); v.accept().await.expect("Failed to accept verification");
let emoji_str = v let emoji_str = v.emoji().map_or_else(
.emoji() || "No emojis".to_string(),
.map(|emojis| { |emojis| {
emojis emojis
.iter() .iter()
.map(|e| format!("{} ({})", e.symbol, e.description)) .map(|e| format!("{} ({})", e.symbol, e.description))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")
}) },
.unwrap_or_else(|| "No emojis".to_string()); );
let decimals = v let decimals = v.decimals().map_or_else(
.decimals() || "No decimals".to_string(),
.map(|(n1, n2, n3)| format!("{} {} {}", n1, n2, n3)) |(n1, n2, n3)| format!("[{n1}, {n2}, {n3}]"),
.unwrap_or_else(|| "No decimals".to_string()); );
if prompt( if prompt(
&mut stdin, &mut stdin,
@ -330,12 +335,14 @@ impl MatrixClient {
println!( println!(
"Verification for {}:\nEmoji: {}\nDecimals: [{}, {}, {}]\n Confirm? (y/n)", "Verification for {}:\nEmoji: {}\nDecimals: [{}, {}, {}]\n Confirm? (y/n)",
device.device_id(), device.device_id(),
emojis.map(|e| e.emojis emojis.map_or_else(
.iter() || "No emojis".to_string(),
.map(|e| format!("{} ({})", e.symbol, e.description)) |e| e.emojis
.collect::<Vec<_>>() .iter()
.join(", "), .map(|e| format!("{} ({})", e.symbol, e.description))
).unwrap_or_else(|| "No emojis".to_string()), .collect::<Vec<_>>()
.join(", "),
),
decimals.0, decimals.1, decimals.2 decimals.0, decimals.1, decimals.2
); );
@ -385,6 +392,7 @@ impl MatrixClient {
false false
} }
#[allow(clippy::must_use_candidate)]
pub fn room_messages( pub fn room_messages(
room: &Room, room: &Room,
since: Option<String>, since: Option<String>,

View file

@ -36,7 +36,7 @@ pub enum DecryptError {
VersionMismatch, VersionMismatch,
} }
pub async fn try_decrypt<'s, E>( pub fn try_decrypt<'s, E>(
jwk: &JsonWebKey, jwk: &JsonWebKey,
data: impl TryStream<Ok = Vec<u8>, Error = E> + Send + 's, data: impl TryStream<Ok = Vec<u8>, Error = E> + Send + 's,
iv: &[u8], iv: &[u8],
@ -64,6 +64,7 @@ pub struct VerifyingStream<'a, S> {
} }
impl<'a, S> VerifyingStream<'a, S> { impl<'a, S> VerifyingStream<'a, S> {
#[must_use]
pub fn new(inner: Pin<Box<S>>, expected: &'a [u8]) -> Self { pub fn new(inner: Pin<Box<S>>, expected: &'a [u8]) -> Self {
Self { Self {
inner, inner,
@ -120,5 +121,5 @@ pub async fn decrypt_file<'s, E: std::error::Error + 's>(
sha256_expect, sha256_expect,
)); ));
try_decrypt(&file.key, data, iv).await try_decrypt(&file.key, data, iv)
} }

View file

@ -3,6 +3,7 @@ use ruma_client_api::{
sync::sync_events::v3::Filter, sync::sync_events::v3::Filter,
}; };
#[must_use]
pub fn minimal_sync_filter() -> Filter { pub fn minimal_sync_filter() -> Filter {
let mut filter = FilterDefinition::empty(); let mut filter = FilterDefinition::empty();
@ -19,7 +20,7 @@ pub fn minimal_sync_filter() -> Filter {
"m.room.avatar", "m.room.avatar",
] ]
.into_iter() .into_iter()
.map(|s| s.to_string()) .map(ToString::to_string)
.collect(), .collect(),
); );
room_filter.timeline = room_event_filter; room_filter.timeline = room_event_filter;

View file

@ -1,3 +1,4 @@
#[must_use]
pub fn sanitize_filename(name: &str) -> String { pub fn sanitize_filename(name: &str) -> String {
name.chars() name.chars()
.map(|c| match c { .map(|c| match c {

View file

@ -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::{ use std::{
fs::OpenOptions, fs::OpenOptions,
os::unix::fs::OpenOptionsExt, os::unix::fs::OpenOptionsExt,
@ -75,6 +80,7 @@ pub struct Args {
pub key_sync_timeout: u64, pub key_sync_timeout: u64,
} }
#[must_use]
pub fn mxc_url_to_https(mxc_url: &str, homeserver: &str) -> String { pub fn mxc_url_to_https(mxc_url: &str, homeserver: &str) -> String {
format!( format!(
"{}_matrix/media/r0/download/{}", "{}_matrix/media/r0/download/{}",
@ -113,6 +119,7 @@ pub enum DumpError {
InvalidId(#[from] IdParseError), InvalidId(#[from] IdParseError),
} }
#[allow(clippy::too_many_lines)]
pub async fn dump_room_messages( pub async fn dump_room_messages(
room: &matrix_sdk::Room, room: &matrix_sdk::Room,
out_dir: &Path, out_dir: &Path,
@ -135,7 +142,7 @@ pub async fn dump_room_messages(
let mut out = Vec::with_capacity(msg.len()); let mut out = Vec::with_capacity(msg.len());
for event in msg.into_iter() { for event in msg {
let mut fm = None; let mut fm = None;
match event.event.clone().cast::<AnyTimelineEvent>().deserialize() { match event.event.clone().cast::<AnyTimelineEvent>().deserialize() {
Ok(event) => { Ok(event) => {
@ -235,6 +242,7 @@ pub async fn dump_room_messages(
Ok(()) Ok(())
} }
#[allow(clippy::too_many_lines)]
pub async fn run( pub async fn run(
js: &mut JoinSet<Result<(), DumpError>>, js: &mut JoinSet<Result<(), DumpError>>,
bg_js: &mut JoinSet<Result<(), DumpError>>, bg_js: &mut JoinSet<Result<(), DumpError>>,
@ -352,6 +360,7 @@ pub async fn run(
{ {
log::info!("Starting E2E setup"); log::info!("Starting E2E setup");
#[allow(clippy::match_bool, clippy::single_match_else)]
match client.clone().setup_e2e().await { match client.clone().setup_e2e().await {
true => log::info!("E2E setup done"), true => log::info!("E2E setup done"),
false => log::error!("E2E setup failed, E2E will not be decrypted"), 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())); .unwrap_or(room.name().unwrap_or("unknown".to_string()));
let room_dir = 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() { let match_filter = if filter.is_empty() {
true true