diff --git a/Cargo.toml b/Cargo.toml index 57af137..4e41169 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Michael Zhang "] description = "cli tool for interacting with the freedesktop trashcan" repository = "https://git.sr.ht/~iptq/garbage" license = "GPL-3.0" -edition = "2018" +edition = "2021" [[bin]] name = "garbage" diff --git a/src/dir.rs b/src/dir.rs index b4efc1f..bdbc5e0 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -36,7 +36,7 @@ impl TrashDir { /// If the option is None, then the home trash will be selected instead. pub fn from_opt(opt: Option>) -> Self { opt.map(|path| TrashDir::from(path.as_ref().to_path_buf())) - .unwrap_or_else(|| TrashDir::get_home_trash()) + .unwrap_or_else(TrashDir::get_home_trash) } /// Actually create the directory on disk corresponding to this trash diff --git a/src/errors.rs b/src/errors.rs index 3b8a759..749066f 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -71,7 +71,7 @@ pub struct MultipleErrors(Vec); impl fmt::Display for MultipleErrors { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - writeln!(f, "")?; + writeln!(f)?; for err in self.0.iter() { writeln!(f, "- {}", err)?; } diff --git a/src/info.rs b/src/info.rs index a52ae26..015ee42 100644 --- a/src/info.rs +++ b/src/info.rs @@ -14,11 +14,7 @@ const DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:%S"; fn parse_key_value(line: &str) -> Option<(&str, &str)> { let mut parts = line.split('=').peekable(); - let key = if let Some(key) = parts.next() { - key - } else { - return None; - }; + let key = parts.next()?; let value = &line[key.len() + 1..]; Some((key, value)) diff --git a/src/main.rs b/src/main.rs index aff597b..91aaa16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,11 +5,11 @@ extern crate log; use std::process::exit; +use clap::{crate_version, Parser}; use garbage::{ ops::{self, EmptyOptions, ListOptions, PutOptions, RestoreOptions}, Result, }; -use clap::{Parser, crate_version}; #[derive(Parser)] #[clap(about, version = concat!(crate_version!(), "-", env!("GIT_HASH")), author)] diff --git a/src/ops/empty.rs b/src/ops/empty.rs index b102492..9ffda7e 100644 --- a/src/ops/empty.rs +++ b/src/ops/empty.rs @@ -50,7 +50,7 @@ pub fn empty(options: EmptyOptions) -> Result<()> { // ignore files that were deleted after the cutoff (younger) .filter(|info| info.deletion_date <= cutoff) .filter(|info| options.all || info.path.starts_with(¤t_dir)) - .map(|info| -> Result<_> { + .try_for_each(|info| -> Result<_> { if options.dry { println!("deleting {:?}", info.path); } else { @@ -66,8 +66,7 @@ pub fn empty(options: EmptyOptions) -> Result<()> { } Ok(()) - }) - .collect::>()?; + })?; Ok(()) } diff --git a/src/ops/list.rs b/src/ops/list.rs index 5cc6f7e..53f744d 100644 --- a/src/ops/list.rs +++ b/src/ops/list.rs @@ -29,13 +29,7 @@ pub fn list(options: ListOptions) -> Result<()> { .iter()? .collect::>>()? .into_iter() - .filter_map(|info| { - if !options.all && !info.path.starts_with(¤t_dir) { - None - } else { - Some(info) - } - }) + .filter(|info| options.all || info.path.starts_with(¤t_dir)) .collect::>(); files.sort_unstable_by_key(|info| info.deletion_date); diff --git a/src/ops/put.rs b/src/ops/put.rs index c2d8026..258c6ca 100644 --- a/src/ops/put.rs +++ b/src/ops/put.rs @@ -132,7 +132,7 @@ impl DeletionStrategy { let target = target.as_ref(); let target_mount = MOUNTS .get_mount_point(target) - .ok_or_else(|| PutError::CouldntFindMountPoint)?; + .ok_or(PutError::CouldntFindMountPoint)?; // first, are we on the home mount? if target_mount == *HOME_MOUNT { @@ -142,6 +142,7 @@ impl DeletionStrategy { // try to use the $topdir/.Trash directory // NOTE: really wish i could break from if statements... + #[allow(clippy::never_loop)] 'topdir: while should_use_topdir_trash(&target_mount) { let topdir_trash_dir = target_mount .join(".Trash") @@ -313,5 +314,5 @@ fn should_use_topdir_trash_uid(path: impl AsRef) -> bool { Err(_) => return false, }; } - return true; + true } diff --git a/src/ops/restore.rs b/src/ops/restore.rs index 66e10ee..a3b147a 100644 --- a/src/ops/restore.rs +++ b/src/ops/restore.rs @@ -53,7 +53,7 @@ pub fn restore(options: RestoreOptions) -> Result<()> { files }; - if files.len() == 0 { + if files.is_empty() { return Err(Error::NoFilesInThisDirectory( trash_dir.path().to_path_buf(), )); diff --git a/src/utils.rs b/src/utils.rs index 10c218d..31519d5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -60,7 +60,7 @@ pub fn recursive_copy( let relative_path = path.strip_prefix(src)?; // this must be the root - if let None = relative_path.file_name() { + if relative_path.file_name().is_none() { fs::create_dir(dst)?; continue; } @@ -101,7 +101,7 @@ pub fn percent_encode(path: impl AsRef) -> String { .join(&MAIN_SEPARATOR.to_string()) } -pub(crate) fn concat_os_str_iter<'a>(ss: &Vec<&'a OsStr>) -> OsString { +pub(crate) fn concat_os_str_iter(ss: &[&OsStr]) -> OsString { let mut len = 0; for s in ss { len += s.len();