11//! Filesystem operations for [`Resolve`].
22
3- use alloc:: collections:: BTreeMap ;
43use alloc:: format;
5- use alloc:: string:: ToString ;
6- use alloc:: vec;
74use std:: path:: Path ;
85use std:: vec:: Vec ;
96
107use anyhow:: { Context , Result , bail} ;
118
129use super :: { PackageSources , Resolve } ;
13- use crate :: { IndexSet , UnresolvedPackageGroup } ;
10+ use crate :: UnresolvedPackageGroup ;
1411
1512/// All the sources used during resolving a directory or path.
1613#[ derive( Clone , Debug ) ]
@@ -24,10 +21,7 @@ impl PackageSourceMap {
2421 . to_str ( )
2522 . ok_or_else ( || anyhow:: anyhow!( "path is not valid utf-8: {:?}" , source) ) ?;
2623 Ok ( Self {
27- inner : PackageSources {
28- sources : vec ! [ vec![ path_str. to_string( ) ] ] ,
29- package_id_to_source_map_idx : BTreeMap :: from ( [ ( package_id, 0 ) ] ) ,
30- } ,
24+ inner : PackageSources :: from_single_source ( package_id, path_str) ,
3125 } )
3226 }
3327
@@ -37,24 +31,14 @@ impl PackageSourceMap {
3731
3832 /// All unique source paths.
3933 pub fn paths ( & self ) -> impl Iterator < Item = & Path > {
40- // Usually any two source map should not have duplicated source paths,
41- // but it can happen, e.g. with using [`Resolve::push_str`] directly.
42- // To be sure we use a set for deduplication here.
43- self . inner
44- . sources
45- . iter ( )
46- . flatten ( )
47- . map ( |s| Path :: new ( s) )
48- . collect :: < IndexSet < & Path > > ( )
49- . into_iter ( )
34+ self . inner . source_names ( ) . map ( Path :: new)
5035 }
5136
5237 /// Source paths for package
5338 pub fn package_paths ( & self , id : super :: PackageId ) -> Option < impl Iterator < Item = & Path > > {
5439 self . inner
55- . package_id_to_source_map_idx
56- . get ( & id)
57- . map ( |& idx| self . inner . sources [ idx] . iter ( ) . map ( |s| Path :: new ( s) ) )
40+ . package_source_names ( id)
41+ . map ( |iter| iter. map ( Path :: new) )
5842 }
5943}
6044
0 commit comments