From 9d5e69192413ce502a4ce81eb73d6bcff9da7ddc Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Mon, 13 Feb 2023 20:54:49 +0100 Subject: [PATCH] fix more lints --- crates/core/src/backend/actual/pacman.rs | 2 +- crates/core/src/backend/actual/rust.rs | 2 +- crates/core/src/backend/backend_trait.rs | 2 +- crates/core/src/backend/iter.rs | 2 +- crates/core/src/backend/mod.rs | 6 +++--- crates/core/src/backend/todo_per_backend.rs | 2 +- crates/core/src/core.rs | 3 ++- crates/core/src/env.rs | 4 ++-- crates/core/src/grouping/package.rs | 18 ++++++++++-------- crates/core/src/path.rs | 6 +++--- crates/core/src/search.rs | 2 +- crates/core/src/ui.rs | 4 ++-- 12 files changed, 28 insertions(+), 25 deletions(-) diff --git a/crates/core/src/backend/actual/pacman.rs b/crates/core/src/backend/actual/pacman.rs index 03bb40d..98d88c9 100644 --- a/crates/core/src/backend/actual/pacman.rs +++ b/crates/core/src/backend/actual/pacman.rs @@ -9,7 +9,7 @@ use crate::backend::backend_trait::*; use crate::{impl_backend_constants, Group, Package}; #[derive(Debug)] -pub(crate) struct Pacman { +pub struct Pacman { pub(crate) binary: String, pub(crate) aur_rm_args: Option>, pub(crate) packages: HashSet, diff --git a/crates/core/src/backend/actual/rust.rs b/crates/core/src/backend/actual/rust.rs index a1170f9..c825c71 100644 --- a/crates/core/src/backend/actual/rust.rs +++ b/crates/core/src/backend/actual/rust.rs @@ -10,7 +10,7 @@ use crate::backend::backend_trait::*; use crate::{impl_backend_constants, Group, Package}; #[derive(Debug)] -pub(crate) struct Rust { +pub struct Rust { pub(crate) packages: HashSet, } diff --git a/crates/core/src/backend/backend_trait.rs b/crates/core/src/backend/backend_trait.rs index 3dfe7fb..71a8f1e 100644 --- a/crates/core/src/backend/backend_trait.rs +++ b/crates/core/src/backend/backend_trait.rs @@ -11,7 +11,7 @@ use crate::{Group, Package}; pub(in crate::backend) type Switches = &'static [&'static str]; pub(in crate::backend) type Text = &'static str; -pub(crate) trait Backend: Debug { +pub trait Backend: Debug { fn get_binary(&self) -> Text; fn get_section(&self) -> Text; diff --git a/crates/core/src/backend/iter.rs b/crates/core/src/backend/iter.rs index 0b803ea..912e4c2 100644 --- a/crates/core/src/backend/iter.rs +++ b/crates/core/src/backend/iter.rs @@ -1,7 +1,7 @@ use super::{Backend, Backends}; #[derive(Debug)] -pub(crate) struct BackendIter { +pub struct BackendIter { pub(crate) next: Option, } diff --git a/crates/core/src/backend/mod.rs b/crates/core/src/backend/mod.rs index c694c34..ecade70 100644 --- a/crates/core/src/backend/mod.rs +++ b/crates/core/src/backend/mod.rs @@ -4,9 +4,9 @@ mod iter; mod macros; mod todo_per_backend; -pub(crate) use backend_trait::Backend; -pub(crate) use iter::BackendIter; -pub(crate) use todo_per_backend::ToDoPerBackend; +pub use backend_trait::Backend; +pub use iter::BackendIter; +pub use todo_per_backend::ToDoPerBackend; use ::macros::Register; diff --git a/crates/core/src/backend/todo_per_backend.rs b/crates/core/src/backend/todo_per_backend.rs index d1a312b..bae2108 100644 --- a/crates/core/src/backend/todo_per_backend.rs +++ b/crates/core/src/backend/todo_per_backend.rs @@ -6,7 +6,7 @@ use super::Backend; use crate::Package; #[derive(Debug)] -pub(crate) struct ToDoPerBackend(Vec<(Box, Vec)>); +pub struct ToDoPerBackend(Vec<(Box, Vec)>); impl ToDoPerBackend { pub(crate) fn new() -> Self { diff --git a/crates/core/src/core.rs b/crates/core/src/core.rs index ea61830..c2c6664 100644 --- a/crates/core/src/core.rs +++ b/crates/core/src/core.rs @@ -307,6 +307,7 @@ fn get_assumed_group_file_names(arg_match: &ArgMatches) -> Result> Ok(paths) } +#[allow(clippy::option_if_let_else)] fn show_error(error: &anyhow::Error, backend: &dyn Backend) { let section = backend.get_section(); match get_single_var("RUST_BACKTRACE") { @@ -319,7 +320,7 @@ fn show_error(error: &anyhow::Error, backend: &dyn Backend) { } } -pub(crate) const fn get_version_string() -> &'static str { +pub const fn get_version_string() -> &'static str { concat!( "pacdef, version: ", env!("CARGO_PKG_VERSION"), diff --git a/crates/core/src/env.rs b/crates/core/src/env.rs index 8b73725..4172f1b 100644 --- a/crates/core/src/env.rs +++ b/crates/core/src/env.rs @@ -2,7 +2,7 @@ use std::env::var; use anyhow::{anyhow, Result}; -pub(crate) fn get_editor() -> Result { +pub fn get_editor() -> Result { check_vars_in_order(&["EDITOR", "VISUAL"]).ok_or_else(|| anyhow!("could not find editor")) } @@ -10,6 +10,6 @@ fn check_vars_in_order(vars: &[&str]) -> Option { vars.iter().find_map(|v| var(v).ok()) } -pub(crate) fn get_single_var(variable: &str) -> Option { +pub fn get_single_var(variable: &str) -> Option { var(variable).ok() } diff --git a/crates/core/src/grouping/package.rs b/crates/core/src/grouping/package.rs index 40ecfd1..c3fda26 100644 --- a/crates/core/src/grouping/package.rs +++ b/crates/core/src/grouping/package.rs @@ -48,14 +48,16 @@ impl Package { impl PartialEq for Package { fn eq(&self, other: &Self) -> bool { - self.name == other.name - && match &self.repo { - None => true, - Some(r) => match &other.repo { - None => true, - Some(r2) => r == r2, - }, - } + let self_repo = self.repo.as_ref(); + let other_repo = other.repo.as_ref(); + + // iff both packages have repos, they must be identical, otherwise we don't care + let repos_are_identical = + self_repo.map_or(true, |sr| other_repo.map_or(true, |or| sr == or)); + + let names_are_identical = self.name == other.name; + + names_are_identical && repos_are_identical } } diff --git a/crates/core/src/path.rs b/crates/core/src/path.rs index 59e3eb6..8d0d616 100644 --- a/crates/core/src/path.rs +++ b/crates/core/src/path.rs @@ -2,13 +2,13 @@ use std::{env, path::PathBuf}; use anyhow::{Context, Result}; -pub(crate) fn get_pacdef_group_dir() -> Result { +pub fn get_pacdef_group_dir() -> Result { let mut result = get_pacdef_base_dir().context("getting pacdef base dir")?; result.push("groups"); Ok(result) } -pub(crate) fn get_pacdef_base_dir() -> Result { +pub fn get_pacdef_base_dir() -> Result { let mut dir = get_xdg_config_home().context("getting XDG_CONFIG_HOME")?; dir.push("pacdef"); Ok(dir) @@ -24,6 +24,6 @@ fn get_xdg_config_home() -> Result { } } -pub(crate) fn get_home_dir() -> Result { +pub fn get_home_dir() -> Result { Ok(env::var("HOME").context("getting $HOME variable")?.into()) } diff --git a/crates/core/src/search.rs b/crates/core/src/search.rs index 960d4c3..17e94f5 100644 --- a/crates/core/src/search.rs +++ b/crates/core/src/search.rs @@ -10,7 +10,7 @@ use crate::grouping::{Group, Package, Section}; pub const NO_PACKAGES_FOUND: &str = "no packages matching query"; -pub(crate) fn search_packages(args: &ArgMatches, groups: &HashSet) -> Result<()> { +pub fn search_packages(args: &ArgMatches, groups: &HashSet) -> Result<()> { let search_string = args .get_one::("string") .context("getting search string from arg")?; diff --git a/crates/core/src/ui.rs b/crates/core/src/ui.rs index fc26703..4280336 100644 --- a/crates/core/src/ui.rs +++ b/crates/core/src/ui.rs @@ -3,7 +3,7 @@ use std::io::{self, Read, Write}; use anyhow::{Context, Result}; use termios::*; -pub(crate) fn get_user_confirmation() -> Result { +pub fn get_user_confirmation() -> Result { print!("Continue? [Y/n] "); std::io::stdout().flush().context("flushing stdout")?; @@ -15,7 +15,7 @@ pub(crate) fn get_user_confirmation() -> Result { Ok(reply.trim().is_empty() || reply.to_lowercase().contains('y')) } -pub(crate) fn read_single_char_from_terminal() -> Result { +pub fn read_single_char_from_terminal() -> Result { // 0 is the file descriptor for stdin let fd = 0; let termios = Termios::from_fd(fd).context("getting stdin fd")?;