MCPcopy Index your code
hub / github.com/RustPython/RustPython / search_up

Function search_up

crates/vm/src/getpath.rs:72–89  ·  view source on GitHub ↗

Search upward from a directory for landmark files/directories Returns the directory where a landmark was found

(start: P, landmarks: &[&str], test: F)

Source from the content-addressed store, hash-verified

70/// Search upward from a directory for landmark files/directories
71/// Returns the directory where a landmark was found
72fn search_up<P, F>(start: P, landmarks: &[&str], test: F) -> Option<PathBuf>
73where
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
92fn search_up_file<P: AsRef<Path>>(start: P, landmarks: &[&str]) -> Option<PathBuf> {

Callers 2

search_up_fileFunction · 0.85
search_up_dirFunction · 0.85

Calls 6

to_path_bufMethod · 0.80
testFunction · 0.50
SomeClass · 0.50
as_refMethod · 0.45
joinMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected