From b705459c3bfde78a33701bf8ba7e91b08670f439 Mon Sep 17 00:00:00 2001 From: Eduardo Flores Date: Thu, 11 Jul 2024 09:15:22 -0700 Subject: [PATCH] chore: clippy --- src/app.rs | 50 ++++++++++++++++----------------------------- src/app/key_bind.rs | 4 ---- src/app/localize.rs | 2 +- src/app/settings.rs | 2 +- src/content.rs | 8 ++------ src/todo.rs | 6 +++--- 6 files changed, 25 insertions(+), 47 deletions(-) diff --git a/src/app.rs b/src/app.rs index 7bbb0e3..2733265 100644 --- a/src/app.rs +++ b/src/app.rs @@ -120,8 +120,6 @@ pub struct Flags { #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Action { About, - ItemDown, - ItemUp, Settings, WindowClose, WindowNew, @@ -136,8 +134,6 @@ impl MenuAction for Action { fn message(&self) -> Self::Message { match self { Action::About => Message::ToggleContextPage(ContextPage::About), - Action::ItemDown => Message::Content(content::Message::ItemDown), - Action::ItemUp => Message::Content(content::Message::ItemUp), Action::Settings => Message::ToggleContextPage(ContextPage::Settings), Action::WindowClose => Message::WindowClose, Action::WindowNew => Message::WindowNew, @@ -190,10 +186,7 @@ impl Tasks { hash = short_hash.as_str(), date = date )) - .on_press(Message::LaunchUrl(format!( - "{}/commits/{}", - repository, hash - ))) + .on_press(Message::LaunchUrl(format!("{repository}/commits/{hash}"))) .padding(spacing.space_none) .into(), ]) @@ -221,7 +214,7 @@ impl Tasks { .into() } - fn create_nav_item(&mut self, list: List) -> EntityMut { + fn create_nav_item(&mut self, list: &List) -> EntityMut { self.nav_model .insert() .text(format!( @@ -289,10 +282,7 @@ impl Application for Tasks { } fn dialog(&self) -> Option> { - let dialog_page = match self.dialog_pages.front() { - Some(some) => some, - None => return None, - }; + let dialog_page = self.dialog_pages.front()?; let spacing = theme::active().cosmic().spacing; @@ -372,7 +362,7 @@ impl Application for Tasks { .control( widget::container(scrollable(widget::row::with_children(vec![ widget::flex_row(icon_buttons).into(), - horizontal_space(Length::Fixed(spacing.space_s as f32)).into(), + horizontal_space(Length::Fixed(f32::from(spacing.space_s))).into(), ]))) .height(Length::Fixed(300.0)), ); @@ -604,8 +594,7 @@ impl Application for Tasks { let command = Command::perform( todo::update_task(task, self.service.clone().clone()), |result| match result { - Ok(_) => message::none(), - Err(_) => message::none(), + Ok(()) | Err(_) => message::none(), }, ); commands.push(command); @@ -620,8 +609,7 @@ impl Application for Tasks { self.service.clone().clone(), ), |result| match result { - Ok(_) => message::none(), - Err(_) => message::none(), + Ok(()) | Err(_) => message::none(), }, ); commands.push(command); @@ -631,8 +619,7 @@ impl Application for Tasks { let command = Command::perform( todo::create_task(task, self.service.clone()), |result| match result { - Ok(_) => message::none(), - Err(_) => message::none(), + Ok(()) | Err(_) => message::none(), }, ); commands.push(command); @@ -665,17 +652,17 @@ impl Application for Tasks { Message::NavMenuAction(action) => match action { NavMenuAction::Rename(entity) => { if self.nav_model.data::(entity).is_some() { - commands.push(self.update(Message::OpenRenameListDialog)) + commands.push(self.update(Message::OpenRenameListDialog)); } } NavMenuAction::SetIcon(entity) => { if self.nav_model.data::(entity).is_some() { - commands.push(self.update(Message::OpenIconDialog)) + commands.push(self.update(Message::OpenIconDialog)); } } NavMenuAction::Delete(entity) => { if self.nav_model.data::(entity).is_some() { - commands.push(self.update(Message::OpenDeleteListDialog)) + commands.push(self.update(Message::OpenDeleteListDialog)); } } }, @@ -693,13 +680,13 @@ impl Application for Tasks { } Message::WindowNew => match env::current_exe() { Ok(exe) => match process::Command::new(&exe).spawn() { - Ok(_child) => {} + Ok(_) => {} Err(err) => { - eprintln!("failed to execute {:?}: {}", exe, err); + eprintln!("failed to execute {exe:?}: {err}"); } }, Err(err) => { - eprintln!("failed to get current executable path: {}", err); + eprintln!("failed to get current executable path: {err}"); } }, Message::LaunchUrl(url) => match open::that_detached(&url) { @@ -731,7 +718,7 @@ impl Application for Tasks { } Message::PopulateLists(lists) => { for list in lists { - self.create_nav_item(list); + self.create_nav_item(&list); } let Some(entity) = self.nav_model.iter().next() else { return Command::none(); @@ -741,7 +728,7 @@ impl Application for Tasks { commands.push(command); } Message::Key(modifiers, key) => { - for (key_bind, action) in self.key_binds.iter() { + for (key_bind, action) in &self.key_binds { if key_bind.matches(modifiers, &key) { return self.update(action.message()); } @@ -751,7 +738,7 @@ impl Application for Tasks { self.modifiers = modifiers; } Message::AddList(list) => { - self.create_nav_item(list); + self.create_nav_item(&list); let Some(entity) = self.nav_model.iter().last() else { return Command::none(); }; @@ -763,8 +750,7 @@ impl Application for Tasks { let command = Command::perform( todo::delete_list(list.id().clone(), self.service.clone()), |result| match result { - Ok(_) => message::none(), - Err(_) => message::none(), + Ok(()) | Err(_) => message::none(), }, ); @@ -776,7 +762,7 @@ impl Application for Tasks { } Message::Export(tasks) => { if let Some(list) = self.nav_model.data::(self.nav_model.active()) { - let exported_markdown = todo::export_list(list.clone(), tasks); + let exported_markdown = todo::export_list(list, &tasks); commands.push(self.update(Message::OpenExportDialog(exported_markdown))); } } diff --git a/src/app/key_bind.rs b/src/app/key_bind.rs index a47ace7..a851438 100644 --- a/src/app/key_bind.rs +++ b/src/app/key_bind.rs @@ -21,10 +21,6 @@ pub fn key_binds() -> HashMap { }}; } - bind!([], Key::Named(Named::ArrowDown), ItemDown); - bind!([], Key::Named(Named::ArrowUp), ItemUp); - bind!([Shift], Key::Named(Named::ArrowDown), ItemDown); - bind!([Shift], Key::Named(Named::ArrowUp), ItemUp); bind!([Ctrl], Key::Character("n".into()), NewList); bind!([], Key::Named(Named::Delete), DeleteList); bind!([], Key::Named(Named::Enter), RenameList); diff --git a/src/app/localize.rs b/src/app/localize.rs index 7a53da6..e62a560 100644 --- a/src/app/localize.rs +++ b/src/app/localize.rs @@ -42,6 +42,6 @@ pub fn set_localization() { let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages(); if let Err(error) = localizer.select(&requested_languages) { - eprintln!("Error while loading language for App List {}", error); + eprintln!("Error while loading language for App List {error}"); } } diff --git a/src/app/settings.rs b/src/app/settings.rs index 1696154..2249262 100644 --- a/src/app/settings.rs +++ b/src/app/settings.rs @@ -53,7 +53,7 @@ pub fn migrate(prev_app_id: &str) { let new = dirs::data_local_dir().unwrap().join(Tasks::APP_ID); if prev.exists() { match std::fs::rename(prev, new) { - Ok(_) => log::info!("migrated data to new directory"), + Ok(()) => log::info!("migrated data to new directory"), Err(err) => log::error!("error migrating data: {:?}", err), } } diff --git a/src/content.rs b/src/content.rs index 1ef322d..c7fe99f 100644 --- a/src/content.rs +++ b/src/content.rs @@ -26,8 +26,6 @@ pub enum Message { EditMode(DefaultKey, bool), Export(Vec), Input(String), - ItemDown, - ItemUp, List(Option), Select(Task), SetItems(Vec), @@ -193,8 +191,6 @@ impl Content { commands.push(Command::GetTasks(list.id().clone())); } } - Message::ItemDown => {} - Message::ItemUp => {} Message::TitleUpdate(id, title) => { if let Some(task) = self.tasks.get_mut(id) { task.title = title; @@ -223,10 +219,10 @@ impl Content { } Message::SetItems(tasks) => { self.tasks.clear(); - tasks.into_iter().for_each(|task| { + for task in tasks { let id = self.tasks.insert(task); self.task_input_ids.insert(id, widget::Id::unique()); - }); + } } Message::Select(task) => { commands.push(Command::DisplayTask(task)); diff --git a/src/todo.rs b/src/todo.rs index 93d813f..4d7a6fa 100644 --- a/src/todo.rs +++ b/src/todo.rs @@ -70,8 +70,8 @@ pub async fn delete_task( Ok(()) } -pub fn export_list(list: List, tasks: Vec) -> String { +pub fn export_list(list: &List, tasks: &[Task]) -> String { let markdown = list.markdown(); - let tasks_markdown: String = tasks.iter().map(|task| task.markdown()).collect(); - format!("{}\n{}", markdown, tasks_markdown) + let tasks_markdown: String = tasks.iter().map(Markdown::markdown).collect(); + format!("{markdown}\n{tasks_markdown}") }