summaryrefslogtreecommitdiffstats
path: root/src/history.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-22 20:52:53 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-22 20:52:53 -0400
commit8f0ca37df04355de492b6c26e13999fef35975dd (patch)
treeaff2522fe2867c326c1627d6b19395f91cda7884 /src/history.rs
parent4e81c3c76cd8c04aa2cf912c09817ca75dd27183 (diff)
code cleanup and use more functional code
Diffstat (limited to 'src/history.rs')
-rw-r--r--src/history.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/history.rs b/src/history.rs
index d803f88..0981b9d 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -21,11 +21,15 @@ impl DirHistory {
for curr in ancestors {
match structs::JoshutoDirList::new(curr.to_path_buf().clone(), sort_option) {
Ok(mut s) => {
- for (i, dirent) in s.contents.iter().enumerate() {
- if dirent.path == ancestor {
- s.index = Some(i);
- break;
+ let index = s.contents.iter().enumerate().find_map(|(i, dir)| {
+ if dir.path == ancestor {
+ Some(i)
+ } else {
+ None
}
+ });
+ if let Some(i) = index {
+ s.index = Some(i);
}
self.map.insert(curr.to_path_buf(), s);
}
@@ -65,7 +69,7 @@ impl DirHistory {
Entry::Occupied(mut entry) => {
let dir_entry = entry.get_mut();
if dir_entry.need_update() {
- dir_entry.update_contents(&sort_option).unwrap();
+ dir_entry.update_contents(&sort_option);
}
}
Entry::Vacant(entry) => {