From 40f4d51da8c799e3dfb525b99def8f2812689f6c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 19 Feb 2021 01:05:27 -0500 Subject: clippy --- src/api.rs | 2 +- src/bin/rbw/actions.rs | 5 ++--- src/bin/rbw/commands.rs | 30 ++++++++++++++---------------- src/pinentry.rs | 14 ++++++-------- src/pwgen.rs | 10 ++++++---- 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/api.rs b/src/api.rs index 77a6ee6..ca92e25 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1017,7 +1017,7 @@ fn classify_login_error(error_res: &ConnectErrorRes, code: u16) -> Error { "" => { // bitwarden_rs returns an empty error and error_description for // this case, for some reason - if error_res.error_description == "" { + if error_res.error_description.is_empty() { if let Some(error_model) = error_res.error_model.as_ref() { let message = error_model.message.as_str().to_string(); match message.as_str() { diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs index ec6ba99..75703f9 100644 --- a/src/bin/rbw/actions.rs +++ b/src/bin/rbw/actions.rs @@ -34,7 +34,7 @@ pub fn quit() -> anyhow::Result<()> { .and_then(|p| p.to_str().map(|s| s.to_string())), action: rbw::protocol::Action::Quit, })?; - wait_for_exit(pid)?; + wait_for_exit(pid); Ok(()) } Err(e) => match e.kind() { @@ -148,12 +148,11 @@ fn connect() -> anyhow::Result { }) } -fn wait_for_exit(pid: nix::unistd::Pid) -> anyhow::Result<()> { +fn wait_for_exit(pid: nix::unistd::Pid) { loop { if nix::sys::signal::kill(pid, None).is_err() { break; } std::thread::sleep(std::time::Duration::from_millis(10)); } - Ok(()) } diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 3fa30f4..49c44a4 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -99,8 +99,8 @@ impl DecryptedCipher { for field in &self.fields { displayed |= self.display_field( - field.name.as_deref().unwrap_or_else(|| "(null)"), - Some(field.value.as_deref().unwrap_or_else(|| "")), + field.name.as_deref().unwrap_or("(null)"), + Some(field.value.as_deref().unwrap_or("")), ); } @@ -227,12 +227,11 @@ impl DecryptedCipher { if let Some(given_username) = username { match &self.data { - DecryptedData::Login { username, .. } => { - if let Some(found_username) = username { - if given_username != found_username { - return false; - } - } else { + DecryptedData::Login { + username: Some(found_username), + .. + } => { + if given_username != found_username { return false; } } @@ -273,12 +272,11 @@ impl DecryptedCipher { if let Some(given_username) = username { match &self.data { - DecryptedData::Login { username, .. } => { - if let Some(found_username) = username { - if !found_username.contains(given_username) { - return false; - } - } else { + DecryptedData::Login { + username: Some(found_username), + .. + } => { + if !found_username.contains(given_username) { return false; } } @@ -1391,14 +1389,14 @@ fn parse_editor(contents: &str) -> (Option, Option) { let password = lines.next().map(std::string::ToString::to_string); let mut notes: String = lines - .skip_while(|line| *line == "") + .skip_while(|line| line.is_empty()) .filter(|line| !line.starts_with('#')) .map(|line| format!("{}\n", line)) .collect(); while notes.ends_with('\n') { notes.pop(); } - let notes = if notes == "" { None } else { Some(notes) }; + let notes = if notes.is_empty() { None } else { Some(notes) }; (password, notes) } diff --git a/src/pinentry.rs b/src/pinentry.rs index a4627c2..69bf92c 100644 --- a/src/pinentry.rs +++ b/src/pinentry.rs @@ -86,11 +86,10 @@ where if ncommands == 1 { len = 0; break; - } else { - data.copy_within((nl + 1).., 0); - len -= nl + 1; - ncommands -= 1; } + data.copy_within((nl + 1).., 0); + len -= nl + 1; + ncommands -= 1; } else if data.starts_with(b"D ") { data.copy_within(2..nl, 0); len = nl - 2; @@ -110,11 +109,10 @@ where return Err(Error::PinentryErrorMessage { error: error.to_string(), }); - } else { - return Err(Error::PinentryErrorMessage { - error: format!("unknown error ({})", code), - }); } + return Err(Error::PinentryErrorMessage { + error: format!("unknown error ({})", code), + }); } None => { return Err(Error::PinentryErrorMessage { diff --git a/src/pwgen.rs b/src/pwgen.rs index fa110d6..dc6808f 100644 --- a/src/pwgen.rs +++ b/src/pwgen.rs @@ -18,10 +18,12 @@ pub enum Type { pub fn pwgen(ty: Type, len: usize) -> String { if ty == Type::Diceware { - let mut config = chbs::config::BasicConfig::default(); - config.words = len; - config.capitalize_first = chbs::probability::Probability::Never; - config.capitalize_words = chbs::probability::Probability::Never; + let config = chbs::config::BasicConfig { + words: len, + capitalize_first: chbs::probability::Probability::Never, + capitalize_words: chbs::probability::Probability::Never, + ..chbs::config::BasicConfig::default() + }; return config.to_scheme().generate(); } -- cgit v1.2.3-54-g00ecf