diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-29 16:43:13 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-29 16:43:13 -0400 |
commit | e59e454b110f81a8e13f32cd831a9e721cfffc97 (patch) | |
tree | 5b3ee2be293800b9f12de013386f453dc5bbbba2 /src/history.rs | |
parent | 669d8f2b3476910817e801529738691d3f9c8b97 (diff) |
break down structs.rs into multiple files
Diffstat (limited to 'src/history.rs')
-rw-r--r-- | src/history.rs | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/history.rs b/src/history.rs index 064dffe..c29fefe 100644 --- a/src/history.rs +++ b/src/history.rs @@ -22,28 +22,32 @@ pub trait DirectoryHistory { impl DirectoryHistory for HashMap<PathBuf, JoshutoDirList> { fn populate_to_root(&mut self, pathbuf: &PathBuf, sort_option: &sort::SortOption) { let mut ancestors = pathbuf.ancestors(); - if let Some(mut ancestor) = ancestors.next() { - for curr in ancestors { - match JoshutoDirList::new(curr.to_path_buf().clone(), sort_option) { - Ok(mut s) => { - let index = s.contents.iter().enumerate().find_map(|(i, dir)| { - if dir.path == ancestor { - Some(i) - } else { - None + match ancestors.next() { + None => {} + Some(mut ancestor) => { + for curr in ancestors { + match JoshutoDirList::new(curr.to_path_buf().clone(), sort_option) { + Ok(mut s) => { + 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); } - }); - if let Some(i) = index { - s.index = Some(i); + self.insert(curr.to_path_buf(), s); } - self.insert(curr.to_path_buf(), s); + Err(e) => eprintln!("populate_to_root: {}", e), } - Err(e) => eprintln!("populate_to_root: {}", e), - }; - ancestor = curr; + ancestor = curr; + } } } } + fn pop_or_create( &mut self, path: &Path, |