diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 62597bb33..d1395e0dd 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -3438,7 +3438,7 @@ pub unsafe extern "C" fn dc_accounts_select_account( let accounts = &*accounts; block_on(accounts.select_account(id)) .map(|_| 1) - .unwrap_or_else(|_| 0) + .unwrap_or(0) } #[no_mangle] @@ -3450,7 +3450,7 @@ pub unsafe extern "C" fn dc_accounts_add_account(accounts: *mut dc_accounts_t) - let accounts = &*accounts; - block_on(accounts.add_account()).unwrap_or_else(|_| 0) + block_on(accounts.add_account()).unwrap_or(0) } #[no_mangle] diff --git a/src/chat.rs b/src/chat.rs index f6e097171..08e03190b 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -70,10 +70,7 @@ impl ChatId { /// /// This kind of chat ID can not be used for real chats. pub fn is_special(self) -> bool { - match self.0 { - 0..=DC_CHAT_ID_LAST_SPECIAL => true, - _ => false, - } + matches!(self.0, 0..=DC_CHAT_ID_LAST_SPECIAL) } /// Chat ID which represents the deaddrop chat. diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index ea719ba5a..78c56d752 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1530,7 +1530,7 @@ async fn create_adhoc_grp_id(context: &Context, member_ids: &[u32]) -> String { }, ) .await - .unwrap_or_else(|_| member_cs); + .unwrap_or(member_cs); hex_hash(&members) } @@ -1558,7 +1558,7 @@ async fn search_chat_ids_by_contact_ids( } } if !contact_ids.is_empty() { - contact_ids.sort(); + contact_ids.sort_unstable(); let contact_ids_str = join(contact_ids.iter().map(|x| x.to_string()), ","); context.sql.query_map( format!( diff --git a/src/imap/mod.rs b/src/imap/mod.rs index 92466b76e..fe2c07873 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -476,16 +476,8 @@ impl Imap { // the entry has the format `imap.mailbox.=:` let mut parts = entry.split(':'); ( - parts - .next() - .unwrap_or_default() - .parse() - .unwrap_or_else(|_| 0), - parts - .next() - .unwrap_or_default() - .parse() - .unwrap_or_else(|_| 0), + parts.next().unwrap_or_default().parse().unwrap_or(0), + parts.next().unwrap_or_default().parse().unwrap_or(0), ) } else { (0, 0) diff --git a/src/key.rs b/src/key.rs index 38d7bf2a2..61f32d0b5 100644 --- a/src/key.rs +++ b/src/key.rs @@ -222,7 +222,7 @@ async fn generate_keypair(context: &Context) -> Result { let addr = context .get_config(Config::ConfiguredAddr) .await - .ok_or_else(|| Error::NoConfiguredAddr)?; + .ok_or(Error::NoConfiguredAddr)?; let addr = EmailAddress::new(&addr)?; let _guard = context.generating_key_mutex.lock().await; diff --git a/src/message.rs b/src/message.rs index 1440cc61d..215e11581 100644 --- a/src/message.rs +++ b/src/message.rs @@ -866,13 +866,13 @@ impl From for LotState { impl MessageState { pub fn can_fail(self) -> bool { - match self { + matches!( + self, MessageState::OutPreparing - | MessageState::OutPending - | MessageState::OutDelivered - | MessageState::OutMdnRcvd => true, // OutMdnRcvd can still fail because it could be a group message and only some recipients failed. - _ => false, - } + | MessageState::OutPending + | MessageState::OutDelivered + | MessageState::OutMdnRcvd // OutMdnRcvd can still fail because it could be a group message and only some recipients failed. + ) } } diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 737201720..1fac00535 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -145,7 +145,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> { selfstatus: context .get_config(Config::Selfstatus) .await - .unwrap_or_else(|| default_str), + .unwrap_or(default_str), recipients, timestamp: msg.timestamp_sort, loaded: Loaded::Message { chat }, @@ -183,7 +183,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> { let selfstatus = context .get_config(Config::Selfstatus) .await - .unwrap_or_else(|| default_str); + .unwrap_or(default_str); let timestamp = dc_create_smeared_timestamp(context).await; let res = MimeFactory::<'a, 'b> { diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 40a2b5cc0..0117dd645 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -1153,11 +1153,21 @@ pub(crate) fn parse_message_id(ids: &str) -> Result { } fn is_known(key: &str) -> bool { - match key { - "return-path" | "date" | "from" | "sender" | "reply-to" | "to" | "cc" | "bcc" - | "message-id" | "in-reply-to" | "references" | "subject" => true, - _ => false, - } + matches!( + key, + "return-path" + | "date" + | "from" + | "sender" + | "reply-to" + | "to" + | "cc" + | "bcc" + | "message-id" + | "in-reply-to" + | "references" + | "subject" + ) } #[derive(Debug, Default, Clone)] diff --git a/src/oauth2.rs b/src/oauth2.rs index 4f59f55d3..a5a21d32c 100644 --- a/src/oauth2.rs +++ b/src/oauth2.rs @@ -305,7 +305,7 @@ impl Oauth2 { let mut fqdn: String = String::from(domain.as_ref()); if !fqdn.ends_with('.') { - fqdn.push_str("."); + fqdn.push('.'); } if let Ok(res) = resolver.mx_lookup(fqdn).await { @@ -323,7 +323,7 @@ impl Oauth2 { } async fn get_addr(&self, context: &Context, access_token: impl AsRef) -> Option { - let userinfo_url = self.get_userinfo.unwrap_or_else(|| ""); + let userinfo_url = self.get_userinfo.unwrap_or(""); let userinfo_url = replace_in_uri(&userinfo_url, "$ACCESS_TOKEN", access_token); // should returns sth. as diff --git a/src/scheduler.rs b/src/scheduler.rs index 6f2ea5ac5..7c0582d59 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -415,10 +415,7 @@ impl Scheduler { /// Check if the scheduler is running. pub fn is_running(&self) -> bool { - match self { - Scheduler::Running { .. } => true, - _ => false, - } + matches!(self, Scheduler::Running { .. }) } } diff --git a/src/sql.rs b/src/sql.rs index 1c69649ac..4d19ecd74 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -142,7 +142,7 @@ impl Sql { &self, ) -> Result> { let lock = self.pool.read().await; - let pool = lock.as_ref().ok_or_else(|| Error::SqlNoConnection)?; + let pool = lock.as_ref().ok_or(Error::SqlNoConnection)?; let conn = pool.get()?; Ok(conn) @@ -156,7 +156,7 @@ impl Sql { + FnOnce(r2d2::PooledConnection) -> Result, { let lock = self.pool.read().await; - let pool = lock.as_ref().ok_or_else(|| Error::SqlNoConnection)?; + let pool = lock.as_ref().ok_or(Error::SqlNoConnection)?; let conn = pool.get()?; g(conn) @@ -168,7 +168,7 @@ impl Sql { Fut: Future> + Send, { let lock = self.pool.read().await; - let pool = lock.as_ref().ok_or_else(|| Error::SqlNoConnection)?; + let pool = lock.as_ref().ok_or(Error::SqlNoConnection)?; let conn = pool.get()?; g(conn).await