From 3471bcd7549a4bb8baa51c4691d73d96c8171da8 Mon Sep 17 00:00:00 2001 From: Heitor Augusto <44377258+HeitorAugustoLN@users.noreply.github.com> Date: Sat, 11 Oct 2025 15:50:54 -0300 Subject: [PATCH] refactor: apply clippy fixes --- src/accessibility.rs | 7 ++----- src/main.rs | 4 ++-- src/page/appearance.rs | 12 ++++++------ src/page/keyboard.rs | 4 ++-- src/page/language.rs | 12 ++++++------ src/page/launcher.rs | 2 +- src/page/location.rs | 6 +++--- src/page/new_apps.rs | 2 +- src/page/new_shortcuts.rs | 2 +- src/page/user.rs | 25 ++++++++----------------- src/page/wifi.rs | 4 ++-- src/page/workflow.rs | 2 +- 12 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/accessibility.rs b/src/accessibility.rs index 78194d1..6711594 100644 --- a/src/accessibility.rs +++ b/src/accessibility.rs @@ -26,19 +26,16 @@ pub enum AccessibilityEvent { } #[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)] +#[derive(Default)] pub enum ColorFilter { Greyscale, Deuteranopia, Protanopia, Tritanopia, + #[default] Unknown, } -impl Default for ColorFilter { - fn default() -> Self { - ColorFilter::Unknown - } -} #[derive(Debug, Clone, Copy)] pub enum AccessibilityRequest { diff --git a/src/main.rs b/src/main.rs index a0e8f2e..ce5f9cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,7 +73,7 @@ fn main() -> Result<(), Box> { page::AppMode::GnomeTransition } else { // If being run by the cosmic-initial-setup user, we are in OEM mode. - page::AppMode::NewInstall { create_user: pwd::Passwd::current_user().map_or(false, |current_user| current_user.name == "cosmic-initial-setup") } + page::AppMode::NewInstall { create_user: pwd::Passwd::current_user().is_some_and(|current_user| current_user.name == "cosmic-initial-setup") } }; let mut settings = Settings::default(); @@ -312,7 +312,7 @@ impl Application for App { tasks = tasks.chain( cosmic::Task::future(async { _ = std::process::Command::new("loginctl") - .args(&["terminate-user", "cosmic-initial-setup"]) + .args(["terminate-user", "cosmic-initial-setup"]) .status(); }) .discard(), diff --git a/src/page/appearance.rs b/src/page/appearance.rs index 31ecb15..d842988 100644 --- a/src/page/appearance.rs +++ b/src/page/appearance.rs @@ -12,8 +12,8 @@ use std::{ffi::OsStr, io::Read}; use crate::{fl, page}; -static COSMIC_DARK_PNG: &'static [u8] = include_bytes!("../../res/cosmic-dark.png"); -static COSMIC_LIGHT_PNG: &'static [u8] = include_bytes!("../../res/cosmic-light.png"); +static COSMIC_DARK_PNG: &[u8] = include_bytes!("../../res/cosmic-dark.png"); +static COSMIC_LIGHT_PNG: &[u8] = include_bytes!("../../res/cosmic-light.png"); fn dark_icon() -> widget::image::Handle { widget::image::Handle::from_bytes(COSMIC_DARK_PNG) @@ -38,7 +38,7 @@ impl PartialEq for Theme { impl PartialOrd for Theme { fn partial_cmp(&self, other: &Self) -> Option { - self.name.partial_cmp(&other.name) + Some(self.cmp(other)) } } @@ -146,7 +146,7 @@ impl Page { } } - themes.extend(extra_themes.into_iter()); + themes.extend(extra_themes); } Self { @@ -196,10 +196,10 @@ impl Page { } } - return cosmic::Task::done(page::Message::SetTheme(cosmic::Theme { + cosmic::Task::done(page::Message::SetTheme(cosmic::Theme { theme_type: ThemeType::Custom(Arc::new(theme)), ..cosmic::Theme::default() - })); + })) } } } diff --git a/src/page/keyboard.rs b/src/page/keyboard.rs index 9ec71a5..a264670 100644 --- a/src/page/keyboard.rs +++ b/src/page/keyboard.rs @@ -30,7 +30,7 @@ pub enum Message { impl From for super::Message { fn from(message: Message) -> Self { - super::Message::Keyboard(message).into() + super::Message::Keyboard(message) } } @@ -268,7 +268,7 @@ impl page::Page for Page { } fn open(&mut self) -> cosmic::Task { - return widget::text_input::focus(self.search_id.clone()); + widget::text_input::focus(self.search_id.clone()) } fn completed(&self) -> bool { diff --git a/src/page/language.rs b/src/page/language.rs index 844e310..6b5299d 100644 --- a/src/page/language.rs +++ b/src/page/language.rs @@ -21,7 +21,7 @@ pub enum Message { impl From for super::Message { fn from(message: Message) -> Self { - super::Message::Language(message).into() + super::Message::Language(message) } } @@ -213,7 +213,7 @@ impl super::Page for Page { let current_lang = std::env::var("LANG").ok(); if let Some(lang) = current_lang.as_ref() { - if let Some(locale) = registry.locale(&lang) { + if let Some(locale) = registry.locale(lang) { selected = available_languages.insert(localized_locale(&locale, lang.clone())); } } @@ -248,7 +248,7 @@ impl super::Page for Page { } fn open(&mut self) -> cosmic::Task { - return widget::text_input::focus(self.search_id.clone()); + widget::text_input::focus(self.search_id.clone()) } fn completed(&self) -> bool { @@ -286,7 +286,7 @@ impl super::Page for Page { .spacing(space_xxs), ), ) - .on_press(Message::Select(id.clone())) + .on_press(Message::Select(id)) .class(if selected { theme::Button::Link } else { @@ -305,7 +305,7 @@ impl super::Page for Page { if let Some(first) = first_opt { if self.regex_opt.is_some() { // Select first item if no item is selected and there is a search - search_input = search_input.on_submit(move |_| Message::Select(first.clone())); + search_input = search_input.on_submit(move |_| Message::Select(first)); } } @@ -384,7 +384,7 @@ impl Ord for SystemLocale { impl PartialOrd for SystemLocale { fn partial_cmp(&self, other: &Self) -> Option { - self.display_name.partial_cmp(&other.display_name) + Some(self.cmp(other)) } } diff --git a/src/page/launcher.rs b/src/page/launcher.rs index f6d99e2..f45f8db 100644 --- a/src/page/launcher.rs +++ b/src/page/launcher.rs @@ -6,7 +6,7 @@ use cosmic::{ use crate::{fl, page}; -static LAUNCHER_SVG: &'static [u8] = include_bytes!("../../res/launcher.svg"); +static LAUNCHER_SVG: &[u8] = include_bytes!("../../res/launcher.svg"); pub struct Page { handle: widget::svg::Handle, diff --git a/src/page/location.rs b/src/page/location.rs index ddcdf13..7723647 100644 --- a/src/page/location.rs +++ b/src/page/location.rs @@ -2,7 +2,7 @@ use crate::fl; use crate::page; use cosmic::{Element, Task, cosmic_theme, iced::Alignment, theme, widget}; -static CITIES: &'static [u8] = include_bytes!("../../res/cities.bitcode-v0-6"); +static CITIES: &[u8] = include_bytes!("../../res/cities.bitcode-v0-6"); #[derive(Clone, Debug)] pub enum Message { @@ -66,7 +66,7 @@ impl Page { let timezone = city.timezone.clone(); tokio::spawn(async move { _ = tokio::process::Command::new("timedatectl") - .args(&["set-timezone", &timezone]) + .args(["set-timezone", &timezone]) .status() .await; }); @@ -87,7 +87,7 @@ impl page::Page for Page { } fn open(&mut self) -> cosmic::Task { - return widget::text_input::focus(self.search_id.clone()); + widget::text_input::focus(self.search_id.clone()) } fn completed(&self) -> bool { diff --git a/src/page/new_apps.rs b/src/page/new_apps.rs index c722a93..4743f54 100644 --- a/src/page/new_apps.rs +++ b/src/page/new_apps.rs @@ -6,7 +6,7 @@ use cosmic::{ }; use std::any::Any; -static SCREENSHOT: &'static [u8] = include_bytes!("../../res/new-apps.svg"); +static SCREENSHOT: &[u8] = include_bytes!("../../res/new-apps.svg"); pub struct Page { handle: widget::svg::Handle, diff --git a/src/page/new_shortcuts.rs b/src/page/new_shortcuts.rs index 4fa578c..5573683 100644 --- a/src/page/new_shortcuts.rs +++ b/src/page/new_shortcuts.rs @@ -6,7 +6,7 @@ use cosmic::{ }; use std::any::Any; -static SCREENSHOT: &'static [u8] = include_bytes!("../../res/new-shortcuts.svg"); +static SCREENSHOT: &[u8] = include_bytes!("../../res/new-shortcuts.svg"); pub struct Page { handle: widget::svg::Handle, diff --git a/src/page/user.rs b/src/page/user.rs index 59e7083..7733544 100644 --- a/src/page/user.rs +++ b/src/page/user.rs @@ -340,14 +340,7 @@ where } fn permission_was_denied(result: &zbus::Error) -> bool { - match result { - zbus::Error::MethodError(name, _, _) - if name.as_str() == "org.freedesktop.Accounts.Error.PermissionDenied" => - { - true - } - _ => false, - } + matches!(result, zbus::Error::MethodError(name, _, _) if name.as_str() == "org.freedesktop.Accounts.Error.PermissionDenied") } // TODO: Should we allow deprecated methods? @@ -371,14 +364,12 @@ fn get_encrypt_method() -> String { }; let reader = BufReader::new(login_defs); - for line in reader.lines() { - if let Ok(line) = line { - if !line.trim().is_empty() { - if let Some(index) = line.find(|c: char| c.is_whitespace()) { - let key = line[0..index].trim(); - if key == "ENCRYPT_METHOD" { - value = line[(index + 1)..].trim().to_string(); - } + for line in reader.lines().map_while(Result::ok) { + if !line.trim().is_empty() { + if let Some(index) = line.find(|c: char| c.is_whitespace()) { + let key = line[0..index].trim(); + if key == "ENCRYPT_METHOD" { + value = line[(index + 1)..].trim().to_string(); } } } @@ -389,7 +380,7 @@ fn get_encrypt_method() -> String { fn username_valid(username: &str) -> bool { Regex::new("^[a-z][a-z0-9-]{0,30}$") .unwrap() - .is_match(&username) + .is_match(username) } fn password_valid(password: &str, password_confirm: &str) -> bool { diff --git a/src/page/wifi.rs b/src/page/wifi.rs index 7c34357..dc8c23c 100644 --- a/src/page/wifi.rs +++ b/src/page/wifi.rs @@ -158,7 +158,7 @@ impl super::Page for Page { let view_more: Option> = if self .view_more_popup .as_deref() - .map_or(false, |id| id == network.ssid.as_ref()) + .is_some_and(|id| id == network.ssid.as_ref()) { widget::popover(view_more_button.on_press(Message::ViewMore(None))) .position(widget::popover::Position::Bottom) @@ -355,7 +355,7 @@ pub enum Message { impl From for super::Message { fn from(message: Message) -> Self { - super::Message::WiFi(message).into() + super::Message::WiFi(message) } } diff --git a/src/page/workflow.rs b/src/page/workflow.rs index c22976e..05ba308 100644 --- a/src/page/workflow.rs +++ b/src/page/workflow.rs @@ -6,7 +6,7 @@ use cosmic::{ }; use std::any::Any; -static SCREENSHOT: &'static [u8] = include_bytes!("../../res/workspaces.svg"); +static SCREENSHOT: &[u8] = include_bytes!("../../res/workspaces.svg"); pub struct Page { handle: widget::svg::Handle,