diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 10:36:49 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-24 10:36:49 -0400 |
commit | 6e95a6600679e6787a56ec5ef2a88fe0fbcf031f (patch) | |
tree | 4495e3a2bbb12b96b0b767ab1b844040c7cc4c71 /src/sort.rs | |
parent | e9a0d00d46ba4955f7d45d12aa412462e3daab39 (diff) |
add more error handling
- optimize/cleanup code
Diffstat (limited to 'src/sort.rs')
-rw-r--r-- | src/sort.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/sort.rs b/src/sort.rs index ead49d0..c78541f 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -121,19 +121,13 @@ fn natural_sort_case_insensitive( ) -> cmp::Ordering { let f1_name = f1.file_name_as_string.to_lowercase(); let f2_name = f2.file_name_as_string.to_lowercase(); - if f1_name <= f2_name { - cmp::Ordering::Less - } else { - cmp::Ordering::Greater - } + f1_name.partial_cmp(&f2_name).unwrap_or(cmp::Ordering::Less) } fn natural_sort(f1: &structs::JoshutoDirEntry, f2: &structs::JoshutoDirEntry) -> cmp::Ordering { - if f1.file_name <= f2.file_name { - cmp::Ordering::Less - } else { - cmp::Ordering::Greater - } + f1.file_name + .partial_cmp(&f2.file_name) + .unwrap_or(cmp::Ordering::Less) } fn mtime_sort(file1: &structs::JoshutoDirEntry, file2: &structs::JoshutoDirEntry) -> cmp::Ordering { |