@@ -29,23 +29,19 @@ pub enum FileMatch {
29
29
// A module for searching for libraries
30
30
31
31
pub struct FileSearch < ' a > {
32
- pub sysroot : & ' a Path ,
33
- pub triple : & ' a str ,
34
- pub search_paths : & ' a [ SearchPath ] ,
35
- pub tlib_path : & ' a SearchPath ,
36
- pub kind : PathKind ,
32
+ sysroot : & ' a Path ,
33
+ triple : & ' a str ,
34
+ search_paths : & ' a [ SearchPath ] ,
35
+ tlib_path : & ' a SearchPath ,
36
+ kind : PathKind ,
37
37
}
38
38
39
39
impl < ' a > FileSearch < ' a > {
40
- pub fn for_each_lib_search_path < F > ( & self , mut f : F ) where
41
- F : FnMut ( & SearchPath )
42
- {
43
- let iter = self . search_paths . iter ( ) . filter ( |sp| sp. kind . matches ( self . kind ) ) ;
44
- for search_path in iter {
45
- f ( search_path) ;
46
- }
47
-
48
- f ( self . tlib_path ) ;
40
+ pub fn search_paths ( & self ) -> impl Iterator < Item = & ' a SearchPath > {
41
+ let kind = self . kind ;
42
+ self . search_paths . iter ( )
43
+ . filter ( move |sp| sp. kind . matches ( kind) )
44
+ . chain ( std:: iter:: once ( self . tlib_path ) )
49
45
}
50
46
51
47
pub fn get_lib_path ( & self ) -> PathBuf {
@@ -55,7 +51,7 @@ impl<'a> FileSearch<'a> {
55
51
pub fn search < F > ( & self , mut pick : F )
56
52
where F : FnMut ( & Path , PathKind ) -> FileMatch
57
53
{
58
- self . for_each_lib_search_path ( |search_path| {
54
+ for search_path in self . search_paths ( ) {
59
55
debug ! ( "searching {}" , search_path. dir. display( ) ) ;
60
56
fn is_rlib ( p : & Path ) -> bool {
61
57
p. extension ( ) == Some ( "rlib" . as_ref ( ) )
@@ -78,7 +74,7 @@ impl<'a> FileSearch<'a> {
78
74
}
79
75
}
80
76
}
81
- } ) ;
77
+ }
82
78
}
83
79
84
80
pub fn new ( sysroot : & ' a Path ,
@@ -97,13 +93,11 @@ impl<'a> FileSearch<'a> {
97
93
}
98
94
}
99
95
100
- // Returns a list of directories where target-specific dylibs might be located.
101
- pub fn get_dylib_search_paths ( & self ) -> Vec < PathBuf > {
102
- let mut paths = Vec :: new ( ) ;
103
- self . for_each_lib_search_path ( |search_path| {
104
- paths. push ( search_path. dir . to_path_buf ( ) ) ;
105
- } ) ;
106
- paths
96
+ // Returns just the directories within the search paths.
97
+ pub fn search_path_dirs ( & self ) -> Vec < PathBuf > {
98
+ self . search_paths ( )
99
+ . map ( |sp| sp. dir . to_path_buf ( ) )
100
+ . collect ( )
107
101
}
108
102
109
103
// Returns a list of directories where target-specific tool binaries are located.
0 commit comments