summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-28 20:20:18 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-28 20:20:18 +0100
commit40629afac165ac23da19ebf195075254e670decb (patch)
treea244c4198547fe1a886a2e430b495e990eed90d7
parent4d56184397359fa1dbcf31d13c219ed67f389cde (diff)
replace nested if let Ok with let else
-rw-r--r--build.rs24
-rw-r--r--src/completion.rs8
-rw-r--r--src/filter.rs7
-rw-r--r--src/trash.rs52
4 files changed, 42 insertions, 49 deletions
diff --git a/build.rs b/build.rs
index 2a6dbaea..41f9075a 100644
--- a/build.rs
+++ b/build.rs
@@ -5,19 +5,19 @@ use std::borrow::Borrow;
/// The destination is `~/.config/fm`.
/// If there's already some configuration files, no overwrite is done.
fn main() {
- if let Ok(mut default_config_files) = std::env::current_dir() {
- default_config_files.push("config_files/fm");
+ let Ok(mut default_config_files) = std::env::current_dir() else {
+ eprintln!("Environment variable $PWD should be set. Couldn't find the source folder.");
+ return
+ };
+ default_config_files.push("config_files/fm");
- let config_folder_cow = shellexpand::tilde("~/.config");
- let config_folder: &str = config_folder_cow.borrow();
- let mut copy_options = fs_extra::dir::CopyOptions::new();
- copy_options.skip_exist = true;
+ let config_folder_cow = shellexpand::tilde("~/.config");
+ let config_folder: &str = config_folder_cow.borrow();
+ let mut copy_options = fs_extra::dir::CopyOptions::new();
+ copy_options.skip_exist = true;
- match fs_extra::dir::copy(default_config_files, config_folder, &copy_options) {
- Ok(_) => (),
- Err(e) => eprintln!("{:?}", e),
- }
- } else {
- eprintln!("Environment variable $PWD should be set. Couldn't find the source folder.")
+ match fs_extra::dir::copy(default_config_files, config_folder, &copy_options) {
+ Ok(_) => (),
+ Err(e) => eprintln!("{:?}", e),
}
}
diff --git a/src/completion.rs b/src/completion.rs
index f6cc3d06..50979937 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -144,11 +144,9 @@ impl Completion {
}
fn extend_absolute_paths(&mut self, parent: &str, last_name: &str) {
- if let Ok(path) = std::fs::canonicalize(parent) {
- if let Ok(entries) = fs::read_dir(path) {
- self.extend(&Self::entries_matching_filename(entries, last_name))
- }
- }
+ let Ok(path) = std::fs::canonicalize(parent) else { return };
+ let Ok(entries) = fs::read_dir(path) else { return };
+ self.extend(&Self::entries_matching_filename(entries, last_name))
}
fn extend_relative_paths(&mut self, current_path: &str, last_name: &str) {
diff --git a/src/filter.rs b/src/filter.rs
index 31b11d8f..9f150a55 100644
--- a/src/filter.rs
+++ b/src/filter.rs
@@ -47,11 +47,8 @@ impl FilterKind {
}
fn filter_by_name(fileinfo: &FileInfo, filename: &str) -> bool {
- if let Ok(re) = Regex::new(filename) {
- re.is_match(&fileinfo.filename)
- } else {
- false
- }
+ let Ok(re) = Regex::new(filename) else { return false };
+ re.is_match(&fileinfo.filename)
}
fn filter_directory(fileinfo: &FileInfo) -> bool {
diff --git a/src/trash.rs b/src/trash.rs
index 948689b9..8db683fa 100644
--- a/src/trash.rs
+++ b/src/trash.rs
@@ -87,35 +87,33 @@ DeletionDate={}
let dest_name = Self::remove_extension(dest_name.to_str().unwrap().to_owned())?;
if let Ok(lines) = read_lines(trash_info_file) {
for (index, line_result) in lines.enumerate() {
- if let Ok(line) = line_result.as_ref() {
- if line.starts_with("[Trash Info]") {
- if index == 0 {
- found_trash_info_line = true;
- continue;
- } else {
- return trashinfo_error("[TrashInfo] was found after first line");
- }
+ let Ok(line) = line_result.as_ref() else { continue };
+ if line.starts_with("[Trash Info]") {
+ if index == 0 {
+ found_trash_info_line = true;
+ continue;
+ } else {
+ return trashinfo_error("[TrashInfo] was found after first line");
}
- if line.starts_with("Path=") && option_path.is_none() {
- if !found_trash_info_line {
- return trashinfo_error("Found Path line before TrashInfo");
- }
- let path_part = &line[5..];
- let cow_path_str = url_escape::decode(path_part);
- let path_str = cow_path_str.as_ref();
- option_path = Some(PathBuf::from(path_str));
- } else if line.starts_with("DeletionDate=") && option_deleted_time.is_none()
- {
- if !found_trash_info_line {
- return trashinfo_error("Found DeletionDate line before TrashInfo");
- }
- let deletion_date_str = &line[13..];
- match parsed_date_from_path_info(deletion_date_str) {
- Ok(()) => (),
- Err(e) => return Err(e),
- }
- option_deleted_time = Some(deletion_date_str.to_owned())
+ }
+ if line.starts_with("Path=") && option_path.is_none() {
+ if !found_trash_info_line {
+ return trashinfo_error("Found Path line before TrashInfo");
+ }
+ let path_part = &line[5..];
+ let cow_path_str = url_escape::decode(path_part);
+ let path_str = cow_path_str.as_ref();
+ option_path = Some(PathBuf::from(path_str));
+ } else if line.starts_with("DeletionDate=") && option_deleted_time.is_none() {
+ if !found_trash_info_line {
+ return trashinfo_error("Found DeletionDate line before TrashInfo");
+ }
+ let deletion_date_str = &line[13..];
+ match parsed_date_from_path_info(deletion_date_str) {
+ Ok(()) => (),
+ Err(e) => return Err(e),
}
+ option_deleted_time = Some(deletion_date_str.to_owned())
}
}
}