Search upward from a directory for landmark files/directories Returns the directory where a landmark was found
(start: P, landmarks: &[&str], test: F)
| 70 | /// Search upward from a directory for landmark files/directories |
| 71 | /// Returns the directory where a landmark was found |
| 72 | fn search_up<P, F>(start: P, landmarks: &[&str], test: F) -> Option<PathBuf> |
| 73 | where |
| 74 | P: AsRef<Path>, |
| 75 | F: Fn(&Path) -> bool, |
| 76 | { |
| 77 | let mut current = start.as_ref().to_path_buf(); |
| 78 | loop { |
| 79 | for landmark in landmarks { |
| 80 | let path = current.join(landmark); |
| 81 | if test(&path) { |
| 82 | return Some(current); |
| 83 | } |
| 84 | } |
| 85 | if !current.pop() { |
| 86 | return None; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /// Search upward for a file landmark |
| 92 | fn search_up_file<P: AsRef<Path>>(start: P, landmarks: &[&str]) -> Option<PathBuf> { |