summaryrefslogtreecommitdiffstats
path: root/src/sort.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-21 20:26:24 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-21 20:26:24 -0400
commit1440bb47b469414b82180ddca31392befee5b209 (patch)
tree5c2a2133690b4d6cad3cb43322523a3e7aa0a4f0 /src/sort.rs
parent80aacc9e369f0e6d7458f0624271252886684c01 (diff)
make code more idiomatic
Diffstat (limited to 'src/sort.rs')
-rw-r--r--src/sort.rs23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/sort.rs b/src/sort.rs
index d40016a..ead49d0 100644
--- a/src/sort.rs
+++ b/src/sort.rs
@@ -45,7 +45,7 @@ impl SortOption {
dummy_dir_first
};
- move |f1, f2| dir_cmp(f1, f2).unwrap_or_else(|| rev_cmp(base_cmp(f1, f2)))
+ move |f1, f2| dir_cmp(f1, f2).then_with(|| rev_cmp(base_cmp(f1, f2)))
}
pub fn filter_func(&self) -> fn(&Result<fs::DirEntry, std::io::Error>) -> bool {
@@ -90,23 +90,20 @@ pub fn map_entry_default(
const fn dummy_dir_first(
_: &structs::JoshutoDirEntry,
_: &structs::JoshutoDirEntry,
-) -> Option<cmp::Ordering> {
- None
+) -> cmp::Ordering {
+ cmp::Ordering::Equal
}
-fn dir_first(
- f1: &structs::JoshutoDirEntry,
- f2: &structs::JoshutoDirEntry,
-) -> Option<cmp::Ordering> {
+fn dir_first(f1: &structs::JoshutoDirEntry, f2: &structs::JoshutoDirEntry) -> cmp::Ordering {
let f1_isdir = f1.path.is_dir();
let f2_isdir = f2.path.is_dir();
if f1_isdir && !f2_isdir {
- Some(cmp::Ordering::Less)
+ cmp::Ordering::Less
} else if !f1_isdir && f2_isdir {
- Some(cmp::Ordering::Greater)
+ cmp::Ordering::Greater
} else {
- None
+ cmp::Ordering::Equal
}
}
@@ -115,11 +112,7 @@ const fn dummy_reverse(c: cmp::Ordering) -> cmp::Ordering {
}
fn reverse_ordering(c: cmp::Ordering) -> cmp::Ordering {
- match c {
- cmp::Ordering::Less => cmp::Ordering::Greater,
- cmp::Ordering::Greater => cmp::Ordering::Less,
- x => x,
- }
+ c.reverse()
}
fn natural_sort_case_insensitive(