diff --git a/database/src/database.rs b/database/src/database.rs index 11a4795..48c2227 100644 --- a/database/src/database.rs +++ b/database/src/database.rs @@ -14,7 +14,7 @@ fn validate_message(message: &NewMessage) -> Result<()> { Ok(()) } -#[derive(Debug, Deserialize, PartialEq, Serialize)] +#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct MailboxInfo { pub name: Mailbox, pub message_count: usize, @@ -28,7 +28,7 @@ impl Database { // Create a new Database that uses the provided backend #[must_use] pub fn new(backend: B) -> Self { - Database { backend } + Self { backend } } // Add multiple new messages, returning the new messages diff --git a/database/src/filter.rs b/database/src/filter.rs index 0695df4..015030e 100644 --- a/database/src/filter.rs +++ b/database/src/filter.rs @@ -75,7 +75,7 @@ pub struct Filter { impl Filter { // Create a new message filter pub fn new() -> Self { - Filter::default() + Self::default() } // Add a mailbox filter @@ -114,14 +114,10 @@ impl Filter { .add(Expr::col(MessageIden::Mailbox).like(format!("{mailbox}/%"))) .add(Expr::col(MessageIden::Mailbox).eq(mailbox)) })) - .add_option(self.states.map(|states| { - Expr::col(MessageIden::State).is_in( - states - .iter() - .map(|state| (*state).into()) - .collect::>(), - ) - })) + .add_option( + self.states + .map(|states| Expr::col(MessageIden::State).is_in(states.iter().copied())), + ) } // Determine whether a message filter is unrestricted and matches all messages diff --git a/database/src/http_backend.rs b/database/src/http_backend.rs index be51dcc..644020f 100644 --- a/database/src/http_backend.rs +++ b/database/src/http_backend.rs @@ -25,7 +25,7 @@ impl HttpBackend { .context("Invalid authorization token")?, ); } - Ok(HttpBackend { + Ok(Self { client: Client::builder() .default_headers(headers) .build() diff --git a/database/src/lib.rs b/database/src/lib.rs index e2d7a51..58c3ffd 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -1,5 +1,9 @@ -#![deny(clippy::pedantic)] -#![allow(clippy::missing_errors_doc)] +#![warn(clippy::pedantic, clippy::nursery)] +#![allow( + clippy::future_not_send, + clippy::missing_const_for_fn, + clippy::missing_errors_doc +)] mod backend; mod database; diff --git a/database/src/mailbox.rs b/database/src/mailbox.rs index 9866860..2b5ec61 100644 --- a/database/src/mailbox.rs +++ b/database/src/mailbox.rs @@ -10,9 +10,9 @@ pub struct Mailbox(String); impl Mailbox { // Iterate over the mailbox's ancestor mailboxes, including itself // Mailbox "a/b/c" with produce "a", "a/b", "a/b/c" - pub fn iter_ancestors(&self) -> impl Iterator + '_ { + pub fn iter_ancestors(&self) -> impl Iterator + '_ { let sections = self.0.split('/').collect::>(); - (0..sections.len()).map(move |index| Mailbox(sections[0..=index].join("/"))) + (0..sections.len()).map(move |index| Self(sections[0..=index].join("/"))) } // Return the name of the mailbox without its ancestors @@ -23,7 +23,7 @@ impl Mailbox { // Return true if the mailbox is an ancestor of the other mailbox #[must_use] - pub fn is_ancestor_of(&self, other: &Mailbox) -> bool { + pub fn is_ancestor_of(&self, other: &Self) -> bool { other.0.starts_with(&format!("{}/", self.0)) } } @@ -87,8 +87,8 @@ impl From for String { } impl From for Value { - fn from(value: Mailbox) -> Value { - Value::String(Some(Box::new(value.0))) + fn from(value: Mailbox) -> Self { + Self::String(Some(Box::new(value.0))) } } diff --git a/database/src/message.rs b/database/src/message.rs index 42b4432..0de5986 100644 --- a/database/src/message.rs +++ b/database/src/message.rs @@ -16,9 +16,9 @@ pub enum State { impl Display for State { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.write_str(match self { - State::Unread => "unread", - State::Read => "read", - State::Archived => "archived", + Self::Unread => "unread", + Self::Read => "read", + Self::Archived => "archived", }) } } @@ -28,9 +28,9 @@ impl TryFrom for State { fn try_from(value: u32) -> anyhow::Result { match value { - 0 => Ok(State::Unread), - 1 => Ok(State::Read), - 2 => Ok(State::Archived), + 0 => Ok(Self::Unread), + 1 => Ok(Self::Read), + 2 => Ok(Self::Archived), _ => Err(anyhow!("Invalid message state {}", value)), } } @@ -41,9 +41,9 @@ impl FromStr for State { fn from_str(value: &str) -> Result { match value { - "unread" => Ok(State::Unread), - "read" => Ok(State::Read), - "archived" => Ok(State::Archived), + "unread" => Ok(Self::Unread), + "read" => Ok(Self::Read), + "archived" => Ok(Self::Archived), _ => Err(anyhow!("Invalid message state {}", value)), } } @@ -60,8 +60,8 @@ impl From for u32 { } impl From for Value { - fn from(value: State) -> Value { - Value::Unsigned(Some(value.into())) + fn from(value: State) -> Self { + Self::Unsigned(Some(value.into())) } } diff --git a/database/src/sqlite_backend.rs b/database/src/sqlite_backend.rs index 7d0efea..9124e17 100644 --- a/database/src/sqlite_backend.rs +++ b/database/src/sqlite_backend.rs @@ -32,7 +32,7 @@ impl SqliteBackend { let pool = SqlitePool::connect_with(options) .await .context("Failed to open database")?; - let backend = SqliteBackend { pool }; + let backend = Self { pool }; backend.init().await?; Ok(backend) } @@ -63,7 +63,7 @@ impl SqliteBackend { let pool = SqlitePool::connect_with(options) .await .context("Failed to open database")?; - let backend = SqliteBackend { pool }; + let backend = Self { pool }; // Reset the database let sql = Table::drop() diff --git a/server/src/main.rs b/server/src/main.rs index c8bdbb8..d7679a4 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,4 +1,4 @@ -#![deny(clippy::pedantic)] +#![warn(clippy::pedantic, clippy::nursery)] mod cli;