@@ -29,23 +29,19 @@ pub enum FileMatch {
2929// A module for searching for libraries
3030
3131pub 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 ,
3737}
3838
3939impl < ' 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 ) )
4945 }
5046
5147 pub fn get_lib_path ( & self ) -> PathBuf {
@@ -55,7 +51,7 @@ impl<'a> FileSearch<'a> {
5551 pub fn search < F > ( & self , mut pick : F )
5652 where F : FnMut ( & Path , PathKind ) -> FileMatch
5753 {
58- self . for_each_lib_search_path ( |search_path| {
54+ for search_path in self . search_paths ( ) {
5955 debug ! ( "searching {}" , search_path. dir. display( ) ) ;
6056 fn is_rlib ( p : & Path ) -> bool {
6157 p. extension ( ) == Some ( "rlib" . as_ref ( ) )
@@ -78,7 +74,7 @@ impl<'a> FileSearch<'a> {
7874 }
7975 }
8076 }
81- } ) ;
77+ }
8278 }
8379
8480 pub fn new ( sysroot : & ' a Path ,
@@ -97,13 +93,11 @@ impl<'a> FileSearch<'a> {
9793 }
9894 }
9995
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 ( )
107101 }
108102
109103 // Returns a list of directories where target-specific tool binaries are located.
0 commit comments