@@ -91,17 +91,24 @@ impl ModuleImports {
91
91
92
92
#[ derive( Debug , Default ) ]
93
93
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
94
- pub struct ImportMap ( BTreeMap < SystemPathBuf , ModuleImports > ) ;
94
+ pub struct ImportMap ( BTreeMap < SystemPathBuf , BTreeSet < SystemPathBuf > > ) ;
95
95
96
96
impl ImportMap {
97
- /// Insert a module's imports into the map.
98
- pub fn insert ( & mut self , path : SystemPathBuf , imports : ModuleImports ) {
99
- self . 0 . insert ( path, imports) ;
97
+ /// Create an [`ImportMap`] of file to its dependencies.
98
+ ///
99
+ /// Assumes that the input is a collection of unique file paths and their imports.
100
+ pub fn dependencies ( imports : impl IntoIterator < Item = ( SystemPathBuf , ModuleImports ) > ) -> Self {
101
+ let mut map = ImportMap :: default ( ) ;
102
+ for ( path, imports) in imports {
103
+ map. 0 . insert ( path, imports. 0 ) ;
104
+ }
105
+ map
100
106
}
101
107
102
- /// Reverse the [`ImportMap`], e.g., to convert from dependencies to dependents.
103
- #[ must_use]
104
- pub fn reverse ( imports : impl IntoIterator < Item = ( SystemPathBuf , ModuleImports ) > ) -> Self {
108
+ /// Create an [`ImportMap`] of file to its dependents.
109
+ ///
110
+ /// Assumes that the input is a collection of unique file paths and their imports.
111
+ pub fn dependents ( imports : impl IntoIterator < Item = ( SystemPathBuf , ModuleImports ) > ) -> Self {
105
112
let mut reverse = ImportMap :: default ( ) ;
106
113
for ( path, imports) in imports {
107
114
for import in imports. 0 {
@@ -112,13 +119,3 @@ impl ImportMap {
112
119
reverse
113
120
}
114
121
}
115
-
116
- impl FromIterator < ( SystemPathBuf , ModuleImports ) > for ImportMap {
117
- fn from_iter < I : IntoIterator < Item = ( SystemPathBuf , ModuleImports ) > > ( iter : I ) -> Self {
118
- let mut map = ImportMap :: default ( ) ;
119
- for ( path, imports) in iter {
120
- map. 0 . entry ( path) . or_default ( ) . 0 . extend ( imports. 0 ) ;
121
- }
122
- map
123
- }
124
- }
0 commit comments