From b9621938865d4ad24d7bcee7fdbfa0c9c45978c8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 1 Jan 2024 16:06:10 -0500 Subject: clippy and fmt --- src/bin/rbw-agent/notifications.rs | 4 +-- src/bin/rbw-agent/timeout.rs | 2 +- src/bin/rbw/commands.rs | 59 +++++++++++++++++++------------------- 3 files changed, 33 insertions(+), 32 deletions(-) (limited to 'src/bin') diff --git a/src/bin/rbw-agent/notifications.rs b/src/bin/rbw-agent/notifications.rs index 297fa9c..8176603 100644 --- a/src/bin/rbw-agent/notifications.rs +++ b/src/bin/rbw-agent/notifications.rs @@ -148,7 +148,7 @@ fn parse_message( rmpv::decode::read_value(&mut &data[len_buffer_length..]).ok()?; let unpacked_message = unpacked_messagepack.as_array()?; - let message_type = unpacked_message.get(0)?.as_u64()?; + let message_type = unpacked_message.first()?.as_u64()?; // invocation if message_type != 1 { return None; @@ -159,7 +159,7 @@ fn parse_message( } let args = unpacked_message.get(4)?.as_array()?; - let map = args.get(0)?.as_map()?; + let map = args.first()?.as_map()?; for (k, v) in map { if k.as_str()? == "Type" { let ty = v.as_i64()?; diff --git a/src/bin/rbw-agent/timeout.rs b/src/bin/rbw-agent/timeout.rs index e613ff0..e2aba06 100644 --- a/src/bin/rbw-agent/timeout.rs +++ b/src/bin/rbw-agent/timeout.rs @@ -40,7 +40,7 @@ impl Timeout { futures_util::stream::once(tokio::time::sleep( dur, )) - .map(|_| Event::Timer) + .map(|()| Event::Timer) .boxed(), ); } diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index aa7f5b9..2a4dd12 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -671,16 +671,16 @@ impl std::convert::TryFrom<&String> for ListField { } } -const HELP_PW: &str = r#" +const HELP_PW: &str = r" # The first line of this file will be the password, and the remainder of the # file (after any blank lines after the password) will be stored as a note. # Lines with leading # will be ignored. -"#; +"; -const HELP_NOTES: &str = r#" +const HELP_NOTES: &str = r" # The content of this file will be stored as a note. # Lines with leading # will be ignored. -"#; +"; pub fn config_show() -> anyhow::Result<()> { let config = rbw::config::Config::load()?; @@ -819,8 +819,7 @@ pub fn list(fields: &[String]) -> anyhow::Result<()> { let mut ciphers: Vec = db .entries .iter() - .cloned() - .map(|entry| decrypt_cipher(&entry)) + .map(decrypt_cipher) .collect::>()?; ciphers.sort_unstable_by(|a, b| a.name.cmp(&b.name)); @@ -1193,14 +1192,13 @@ pub fn edit( }; (data, notes, history) } - DecryptedData::SecureNote {} => - { + DecryptedData::SecureNote {} => { let data = rbw::db::EntryData::SecureNote {}; - let editor_content = match decrypted.notes { - Some(notes) => format!("{notes}\n"), - None => format!("\n"), - }; + let editor_content = decrypted.notes.map_or_else( + || "\n".to_string(), + |notes| format!("{notes}\n"), + ); let contents = rbw::edit::edit(&editor_content, HELP_NOTES)?; // prepend blank line to be parsed as pw by `parse_editor` @@ -1415,10 +1413,10 @@ fn find_entry_raw( ) -> anyhow::Result<(rbw::db::Entry, DecryptedCipher)> { let mut matches: Vec<(rbw::db::Entry, DecryptedCipher)> = entries .iter() - .cloned() - .filter(|(_, decrypted_cipher)| { + .filter(|&(_, decrypted_cipher)| { decrypted_cipher.exact_match(name, username, folder, true) }) + .cloned() .collect(); if matches.len() == 1 { @@ -1428,10 +1426,10 @@ fn find_entry_raw( if folder.is_none() { matches = entries .iter() - .cloned() - .filter(|(_, decrypted_cipher)| { + .filter(|&(_, decrypted_cipher)| { decrypted_cipher.exact_match(name, username, folder, false) }) + .cloned() .collect(); if matches.len() == 1 { @@ -1441,10 +1439,10 @@ fn find_entry_raw( matches = entries .iter() - .cloned() - .filter(|(_, decrypted_cipher)| { + .filter(|&(_, decrypted_cipher)| { decrypted_cipher.partial_match(name, username, folder, true) }) + .cloned() .collect(); if matches.len() == 1 { @@ -1454,10 +1452,10 @@ fn find_entry_raw( if folder.is_none() { matches = entries .iter() - .cloned() - .filter(|(_, decrypted_cipher)| { + .filter(|&(_, decrypted_cipher)| { decrypted_cipher.partial_match(name, username, folder, false) }) + .cloned() .collect(); if matches.len() == 1 { return Ok(matches[0].clone()); @@ -1763,8 +1761,11 @@ fn parse_editor(contents: &str) -> (Option, Option) { let mut notes: String = lines .skip_while(|line| line.is_empty()) .filter(|line| !line.starts_with('#')) - .map(|line| format!("{line}\n")) - .collect(); + .fold(String::new(), |mut notes, line| { + notes.push_str(line); + notes.push('\n'); + notes + }); while notes.ends_with('\n') { notes.pop(); } @@ -1848,6 +1849,13 @@ fn generate_totp(secret: &str) -> anyhow::Result { )) } +fn display_field(name: &str, field: Option<&str>, clipboard: bool) -> bool { + field.map_or_else( + || false, + |field| val_display_or_store(clipboard, &format!("{name}: {field}")), + ) +} + #[cfg(test)] mod test { use super::*; @@ -2011,10 +2019,3 @@ mod test { ) } } - -fn display_field(name: &str, field: Option<&str>, clipboard: bool) -> bool { - field.map_or_else( - || false, - |field| val_display_or_store(clipboard, &format!("{name}: {field}")), - ) -} -- cgit v1.2.3-54-g00ecf