From b80bfe5d3fb9b07f17bf00468b51b5c3679bab46 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Tue, 5 Jul 2022 03:57:55 +0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20=20Make=20clippy=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/alpm_helper.rs | 43 ++++++++++++++++---------------------- src/application_browser.rs | 6 +++--- src/utils.rs | 4 ++-- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/alpm_helper.rs b/src/alpm_helper.rs index 80647c6..0818e96 100644 --- a/src/alpm_helper.rs +++ b/src/alpm_helper.rs @@ -7,12 +7,12 @@ pub struct AlpmHelper { pub pkg_list_removal: Vec, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum AlpmHelperResult { - NOTHING, - REMOVE, - ADD, - BOTH, + Nothing, + Remove, + Add, + Both, } impl AlpmHelper { @@ -30,23 +30,19 @@ impl AlpmHelper { } pub fn do_update(&self) -> AlpmHelperResult { - let mut result = AlpmHelperResult::NOTHING; + let mut result = AlpmHelperResult::Nothing; if self.pkg_list_install.is_empty() && self.pkg_list_removal.is_empty() { return result; } - if !self.pkg_list_removal.is_empty() { - if self.install_apps(&self.pkg_list_removal, false) { - result = AlpmHelperResult::REMOVE; - } + if !self.pkg_list_removal.is_empty() && self.install_apps(&self.pkg_list_removal, false) { + result = AlpmHelperResult::Remove; } - if !self.pkg_list_install.is_empty() { - if self.install_apps(&self.pkg_list_install, true) { - if result == AlpmHelperResult::NOTHING { - result = AlpmHelperResult::ADD; - } else { - result = AlpmHelperResult::BOTH; - } + if !self.pkg_list_install.is_empty() && self.install_apps(&self.pkg_list_install, true) { + if result == AlpmHelperResult::Nothing { + result = AlpmHelperResult::Add; + } else { + result = AlpmHelperResult::Both; } } @@ -54,14 +50,14 @@ impl AlpmHelper { } pub fn set_package(&mut self, pkg_name: &String, install: bool, installed: bool) { - if self.to_remove(&pkg_name) { + if self.to_remove(pkg_name) { let index = self.pkg_list_removal.iter().position(|x| *x == *pkg_name).unwrap(); self.pkg_list_removal.remove(index); } else if !install && installed { self.pkg_list_removal.push(String::from(pkg_name)); } - if self.to_install(&pkg_name) { + if self.to_install(pkg_name) { let index = self.pkg_list_install.iter().position(|x| *x == *pkg_name).unwrap(); self.pkg_list_install.remove(index); } else if install && !installed { @@ -70,11 +66,11 @@ impl AlpmHelper { } pub fn to_install(&self, pkg_name: &String) -> bool { - self.pkg_list_install.contains(&pkg_name) + self.pkg_list_install.contains(pkg_name) } pub fn to_remove(&self, pkg_name: &String) -> bool { - self.pkg_list_removal.contains(&pkg_name) + self.pkg_list_removal.contains(pkg_name) } fn install_apps(&self, pkg_list: &Vec, install: bool) -> bool { @@ -97,9 +93,6 @@ impl AlpmHelper { let pacman = pacmanconf::Config::with_opts(None, Some("/etc/pacman.conf"), Some("/")).unwrap(); let alpm = alpm_utils::alpm_with_conf(&pacman).unwrap(); - match alpm.localdb().pkg(pkg_name) { - Ok(_) => true, - _ => false, - } + matches!(alpm.localdb().pkg(pkg_name), Ok(_)) } } diff --git a/src/application_browser.rs b/src/application_browser.rs index ad2bdd4..a26b662 100644 --- a/src/application_browser.rs +++ b/src/application_browser.rs @@ -10,7 +10,7 @@ use gtk::prelude::{ }; use once_cell::sync::Lazy; -use serde_json; + use std::fs; use std::sync::Mutex; @@ -389,7 +389,7 @@ fn on_app_toggle(_cell: >k::CellRendererToggle, path: gtk::TreePath) { fn on_update_system_clicked(_: >k::Button) { let app_browser = unsafe { &mut G_APP_BROWSER.lock().unwrap() }; - if app_browser.alpm_helper.do_update() != AlpmHelperResult::NOTHING { + if app_browser.alpm_helper.do_update() != AlpmHelperResult::Nothing { // reload json for view new apps installed app_browser.reload_app_data(true); } @@ -402,7 +402,7 @@ fn load_groups_data(groups: &serde_json::Value) -> gtk::ListStore { for group in groups.as_array().unwrap() { let g_name = String::from(group["name"].as_str().unwrap()); - store.set(&store.append(), &[(0, &String::from(g_name))]); + store.set(&store.append(), &[(0, &g_name)]); } store diff --git a/src/utils.rs b/src/utils.rs index c0a7118..6710682 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -89,8 +89,8 @@ mod test { #[test] fn check_file() { - assert_eq!(check_regular_file("/etc/fstab"), true); - assert_eq!(check_regular_file("/etc"), false); + assert!(check_regular_file("/etc/fstab")); + assert!(!check_regular_file("/etc")); } #[test]