@@ -6,17 +6,24 @@ use std::collections::HashMap;
6
6
use std:: process:: Command ;
7
7
use std:: { fs:: write, path:: PathBuf } ;
8
8
9
+ // crate data we stored in the toml, can have multiple versions.
10
+ // if so, one TomlKrate maps to several KrateSources
11
+ struct TomlKrate {
12
+ name : String ,
13
+ versions : Vec < String > ,
14
+ }
15
+
9
16
// represents an archive we download from crates.io
10
17
#[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
11
18
struct KrateSource {
12
- version : String ,
13
19
name : String ,
20
+ version : String ,
14
21
}
15
22
16
23
// use this to store the crates when interacting with the crates.toml file
17
24
#[ derive( Debug , Serialize , Deserialize ) ]
18
25
struct CrateList {
19
- crates : HashMap < String , String > ,
26
+ crates : HashMap < String , Vec < String > > ,
20
27
}
21
28
22
29
// represents the extracted sourcecode of a crate
@@ -145,11 +152,24 @@ fn read_crates() -> Vec<KrateSource> {
145
152
let crate_list: CrateList =
146
153
toml:: from_str ( & toml_content) . unwrap_or_else ( |e| panic ! ( "Failed to parse {}: \n {}" , toml_path. display( ) , e) ) ;
147
154
// parse the hashmap of the toml file into a list of crates
148
- crate_list
155
+ let tomlkrates : Vec < TomlKrate > = crate_list
149
156
. crates
150
- . iter ( )
151
- . map ( |( name, version) | KrateSource :: new ( & name, & version) )
152
- . collect ( )
157
+ . into_iter ( )
158
+ . map ( |( name, versions) | TomlKrate { name, versions } )
159
+ . collect ( ) ;
160
+
161
+ // flatten TomlKrates into KrateSources (one TomlKrates may represent several versions of a crate =>
162
+ // multiple kratesources)
163
+ let mut krate_sources = Vec :: new ( ) ;
164
+ tomlkrates. into_iter ( ) . for_each ( |tk| {
165
+ tk. versions . iter ( ) . for_each ( |ver| {
166
+ krate_sources. push ( KrateSource {
167
+ name : tk. name . clone ( ) ,
168
+ version : ver. to_string ( ) ,
169
+ } ) ;
170
+ } )
171
+ } ) ;
172
+ krate_sources
153
173
}
154
174
155
175
// the main fn
0 commit comments