From e7d837d68c665c8f51e1a21cadc210b4b40cc637 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Mon, 28 Apr 2025 16:06:51 -0700 Subject: [PATCH] cargo clippy/fix --- kordophone-db/src/database.rs | 5 +--- kordophone-db/src/models/message.rs | 6 +++++ kordophone-db/src/tests/mod.rs | 6 ++--- kordophone/src/api/http_client.rs | 5 ++-- kordophone/src/api/mod.rs | 6 +++++ kordophoned/src/daemon/mod.rs | 10 ++++---- kordophoned/src/daemon/settings.rs | 10 +------- kordophoned/src/dbus/endpoint.rs | 2 +- kordophoned/src/dbus/server_impl.rs | 36 +++++++++++------------------ kpcli/src/client/mod.rs | 3 +-- kpcli/src/daemon/mod.rs | 2 -- kpcli/src/db/mod.rs | 9 +++----- kpcli/src/printers.rs | 4 ++-- 13 files changed, 43 insertions(+), 61 deletions(-) diff --git a/kordophone-db/src/database.rs b/kordophone-db/src/database.rs index 29a8723..c8d86ac 100644 --- a/kordophone-db/src/database.rs +++ b/kordophone-db/src/database.rs @@ -94,10 +94,7 @@ impl TokenStore for Database { async fn get_token(&mut self) -> Option { self.with_settings(|settings| { let token: Result> = settings.get(TOKEN_KEY); - match token { - Ok(data) => data, - Err(_) => None, - } + token.unwrap_or_default() }).await } diff --git a/kordophone-db/src/models/message.rs b/kordophone-db/src/models/message.rs index 9ef76d9..d16f620 100644 --- a/kordophone-db/src/models/message.rs +++ b/kordophone-db/src/models/message.rs @@ -47,6 +47,12 @@ pub struct MessageBuilder { date: Option, } +impl Default for MessageBuilder { + fn default() -> Self { + Self::new() + } +} + impl MessageBuilder { pub fn new() -> Self { Self { diff --git a/kordophone-db/src/tests/mod.rs b/kordophone-db/src/tests/mod.rs index facc721..1023b9e 100644 --- a/kordophone-db/src/tests/mod.rs +++ b/kordophone-db/src/tests/mod.rs @@ -1,12 +1,10 @@ use crate::{ - database::{Database, DatabaseAccess}, - repository::Repository, + database::{Database, DatabaseAccess}, models::{ conversation::{Conversation, ConversationBuilder}, participant::Participant, message::Message, - }, - settings::Settings, + }, }; // Helper function to compare participants ignoring database IDs diff --git a/kordophone/src/api/http_client.rs b/kordophone/src/api/http_client.rs index ec1c186..2cada8b 100644 --- a/kordophone/src/api/http_client.rs +++ b/kordophone/src/api/http_client.rs @@ -3,7 +3,7 @@ extern crate serde; use std::{path::PathBuf, str}; -use crate::api::{TokenStore, InMemoryTokenStore}; +use crate::api::TokenStore; use hyper::{Body, Client, Method, Request, Uri}; use async_trait::async_trait; @@ -247,7 +247,8 @@ impl HTTPAPIClient { #[cfg(test)] mod test { use super::*; - + use crate::api::InMemoryTokenStore; + #[cfg(test)] fn local_mock_client() -> HTTPAPIClient { let base_url = "http://localhost:5738".parse().unwrap(); diff --git a/kordophone/src/api/mod.rs b/kordophone/src/api/mod.rs index 6ae0243..da9090a 100644 --- a/kordophone/src/api/mod.rs +++ b/kordophone/src/api/mod.rs @@ -42,6 +42,12 @@ pub struct InMemoryTokenStore { token: Option, } +impl Default for InMemoryTokenStore { + fn default() -> Self { + Self::new() + } +} + impl InMemoryTokenStore { pub fn new() -> Self { Self { token: None } diff --git a/kordophoned/src/daemon/mod.rs b/kordophoned/src/daemon/mod.rs index 58dcb44..1e0375c 100644 --- a/kordophoned/src/daemon/mod.rs +++ b/kordophoned/src/daemon/mod.rs @@ -182,7 +182,7 @@ impl Daemon { // Fetch conversations from server let fetched_conversations = client.get_conversations().await?; let db_conversations: Vec = fetched_conversations.into_iter() - .map(|c| kordophone_db::models::Conversation::from(c)) + .map(kordophone_db::models::Conversation::from) .collect(); // Process each conversation @@ -205,7 +205,7 @@ impl Daemon { let messages = client.get_messages(&conversation_id, None, None, last_message_id).await?; let db_messages: Vec = messages.into_iter() - .map(|m| kordophone_db::models::Message::from(m)) + .map(kordophone_db::models::Message::from) .collect(); // Insert each message @@ -221,8 +221,7 @@ impl Daemon { } async fn get_settings(&mut self) -> Result { - let settings = self.database.with_settings(|s| - Settings::from_db(s) + let settings = self.database.with_settings(Settings::from_db ).await?; Ok(settings) @@ -237,8 +236,7 @@ impl Daemon { } async fn get_client_impl(database: &mut Arc>) -> Result> { - let settings = database.with_settings(|s| - Settings::from_db(s) + let settings = database.with_settings(Settings::from_db ).await?; let server_url = settings.server_url diff --git a/kordophoned/src/daemon/settings.rs b/kordophoned/src/daemon/settings.rs index 8d7a8ed..5a3d202 100644 --- a/kordophoned/src/daemon/settings.rs +++ b/kordophoned/src/daemon/settings.rs @@ -8,6 +8,7 @@ mod keys { } #[derive(Debug)] +#[derive(Default)] pub struct Settings { pub server_url: Option, pub username: Option, @@ -41,12 +42,3 @@ impl Settings { } } -impl Default for Settings { - fn default() -> Self { - Self { - server_url: None, - username: None, - credential_item: None, - } - } -} \ No newline at end of file diff --git a/kordophoned/src/dbus/endpoint.rs b/kordophoned/src/dbus/endpoint.rs index 8e9d4f6..a35f371 100644 --- a/kordophoned/src/dbus/endpoint.rs +++ b/kordophoned/src/dbus/endpoint.rs @@ -1,5 +1,5 @@ use log::info; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use dbus_crossroads::Crossroads; use dbus_tokio::connection; diff --git a/kordophoned/src/dbus/server_impl.rs b/kordophoned/src/dbus/server_impl.rs index 6a1523a..4c7a5b6 100644 --- a/kordophoned/src/dbus/server_impl.rs +++ b/kordophoned/src/dbus/server_impl.rs @@ -9,7 +9,6 @@ use crate::daemon::{ DaemonResult, events::{Event, Reply}, settings::Settings, - signals::Signal, }; use crate::dbus::interface::NetBuzzertKordophoneRepository as DbusRepository; @@ -54,9 +53,11 @@ impl DbusRepository for ServerImpl { fn get_conversations(&mut self) -> Result, dbus::MethodErr> { self.send_event_sync(Event::GetAllConversations) - .and_then(|conversations| { + .map(|conversations| { // Convert conversations to DBus property maps - let result = conversations.into_iter().map(|conv| { + + + conversations.into_iter().map(|conv| { let mut map = arg::PropMap::new(); map.insert("guid".into(), arg::Variant(Box::new(conv.guid))); map.insert("display_name".into(), arg::Variant(Box::new(conv.display_name.unwrap_or_default()))); @@ -65,9 +66,7 @@ impl DbusRepository for ServerImpl { map.insert("participants".into(), arg::Variant(Box::new(conv.participants.into_iter().map(|p| p.display_name()).collect::>()))); map.insert("date".into(), arg::Variant(Box::new(conv.date.and_utc().timestamp()))); map - }).collect(); - - Ok(result) + }).collect() }) } @@ -83,17 +82,17 @@ impl DbusRepository for ServerImpl { }; self.send_event_sync(|r| Event::GetMessages(conversation_id, last_message_id_opt, r)) - .and_then(|messages| { - let result = messages.into_iter().map(|msg| { + .map(|messages| { + + + messages.into_iter().map(|msg| { let mut map = arg::PropMap::new(); map.insert("id".into(), arg::Variant(Box::new(msg.id))); map.insert("text".into(), arg::Variant(Box::new(msg.text))); map.insert("date".into(), arg::Variant(Box::new(msg.date.and_utc().timestamp()))); map.insert("sender".into(), arg::Variant(Box::new(msg.sender.display_name()))); map - }).collect(); - - Ok(result) + }).collect() }) } } @@ -121,9 +120,7 @@ impl DbusSettings for ServerImpl { fn server_url(&self) -> Result { self.send_event_sync(Event::GetAllSettings) - .and_then(|settings| { - Ok(settings.server_url.unwrap_or_default()) - }) + .map(|settings| settings.server_url.unwrap_or_default()) } fn set_server_url(&self, value: String) -> Result<(), dbus::MethodErr> { @@ -138,9 +135,7 @@ impl DbusSettings for ServerImpl { fn username(&self) -> Result { self.send_event_sync(Event::GetAllSettings) - .and_then(|settings| { - Ok(settings.username.unwrap_or_default()) - }) + .map(|settings| settings.username.unwrap_or_default()) } fn set_username(&self, value: String) -> Result<(), dbus::MethodErr> { @@ -155,12 +150,7 @@ impl DbusSettings for ServerImpl { fn credential_item(&self) -> Result, dbus::MethodErr> { self.send_event_sync(Event::GetAllSettings) - .and_then(|settings| { - Ok(settings.credential_item.unwrap_or_default()) - }) - .and_then(|item| { - Ok(dbus::Path::new(item).unwrap_or_default()) - }) + .map(|settings| settings.credential_item.unwrap_or_default()).map(|item| dbus::Path::new(item).unwrap_or_default()) } fn set_credential_item(&self, value: dbus::Path<'static>) -> Result<(), dbus::MethodErr> { diff --git a/kpcli/src/client/mod.rs b/kpcli/src/client/mod.rs index 8283c1d..d683593 100644 --- a/kpcli/src/client/mod.rs +++ b/kpcli/src/client/mod.rs @@ -3,7 +3,6 @@ use kordophone::api::http_client::HTTPAPIClient; use kordophone::api::http_client::Credentials; use kordophone::api::InMemoryTokenStore; -use dotenv; use anyhow::Result; use clap::Subcommand; use crate::printers::{ConversationPrinter, MessagePrinter}; @@ -58,7 +57,7 @@ struct ClientCli { impl ClientCli { pub fn new() -> Self { let api = make_api_client_from_env(); - Self { api: api } + Self { api } } pub async fn print_version(&mut self) -> Result<()> { diff --git a/kpcli/src/daemon/mod.rs b/kpcli/src/daemon/mod.rs index 9cf11b2..e159c3f 100644 --- a/kpcli/src/daemon/mod.rs +++ b/kpcli/src/daemon/mod.rs @@ -140,8 +140,6 @@ impl DaemonCli { loop { self.conn.process(std::time::Duration::from_millis(1000))?; } - - Ok(()) } pub async fn config(&mut self, cmd: ConfigCommands) -> Result<()> { diff --git a/kpcli/src/db/mod.rs b/kpcli/src/db/mod.rs index f5198b1..ecd5ce8 100644 --- a/kpcli/src/db/mod.rs +++ b/kpcli/src/db/mod.rs @@ -3,10 +3,7 @@ use clap::Subcommand; use kordophone::APIInterface; use std::{env, path::PathBuf}; -use kordophone_db::{ - database::{Database, DatabaseAccess}, - models::{Conversation, Message}, -}; +use kordophone_db::database::{Database, DatabaseAccess}; use crate::{client, printers::{ConversationPrinter, MessagePrinter}}; #[derive(Subcommand)] @@ -138,7 +135,7 @@ impl DbClient { let mut client = client::make_api_client_from_env(); let fetched_conversations = client.get_conversations().await?; let db_conversations: Vec = fetched_conversations.into_iter() - .map(|c| kordophone_db::models::Conversation::from(c)) + .map(kordophone_db::models::Conversation::from) .collect(); // Process each conversation @@ -153,7 +150,7 @@ impl DbClient { // Fetch and sync messages for this conversation let messages = client.get_messages(&conversation_id, None, None, None).await?; let db_messages: Vec = messages.into_iter() - .map(|m| kordophone_db::models::Message::from(m)) + .map(kordophone_db::models::Message::from) .collect(); // Insert each message diff --git a/kpcli/src/printers.rs b/kpcli/src/printers.rs index 5a7146f..b3af6c2 100644 --- a/kpcli/src/printers.rs +++ b/kpcli/src/printers.rs @@ -148,7 +148,7 @@ impl<'a> ConversationPrinter<'a> { } } -impl<'a> Display for ConversationPrinter<'a> { +impl Display for ConversationPrinter<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.doc.render_fmt(180, f) } @@ -158,7 +158,7 @@ pub struct MessagePrinter<'a> { doc: RcDoc<'a, PrintableMessage> } -impl<'a> Display for MessagePrinter<'a> { +impl Display for MessagePrinter<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.doc.render_fmt(180, f) }