@@ -13,11 +13,9 @@ use cargo::{
13
13
util:: Config ,
14
14
} ;
15
15
use itertools:: Itertools ;
16
- use lazy_static:: lazy_static;
17
16
use serde:: { Deserialize , Serialize } ;
18
17
use std:: {
19
18
collections:: { BTreeMap , BTreeSet , HashSet } ,
20
- fs:: File ,
21
19
io:: Read ,
22
20
} ;
23
21
@@ -52,12 +50,12 @@ pub struct CrateInformation {
52
50
}
53
51
54
52
/// Hand-curated changes to the crate list
55
- #[ derive( Debug , Deserialize ) ]
56
- struct Modifications {
53
+ #[ derive( Debug , Default , Deserialize ) ]
54
+ pub struct Modifications {
57
55
#[ serde( default ) ]
58
- exclusions : Vec < String > ,
56
+ pub exclusions : Vec < String > ,
59
57
#[ serde( default ) ]
60
- additions : BTreeSet < String > ,
58
+ pub additions : BTreeSet < String > ,
61
59
}
62
60
63
61
#[ derive( Debug , Serialize , Clone ) ]
@@ -90,19 +88,6 @@ impl Modifications {
90
88
}
91
89
}
92
90
93
- lazy_static ! {
94
- static ref MODIFICATIONS : Modifications = {
95
- let mut f = File :: open( "crate-modifications.toml" )
96
- . expect( "unable to open crate modifications file" ) ;
97
-
98
- let mut d = Vec :: new( ) ;
99
- f. read_to_end( & mut d)
100
- . expect( "unable to read crate modifications file" ) ;
101
-
102
- toml:: from_slice( & d) . expect( "unable to parse crate modifications file" )
103
- } ;
104
- }
105
-
106
91
fn simple_get ( url : & str ) -> reqwest:: Result < reqwest:: blocking:: Response > {
107
92
reqwest:: blocking:: ClientBuilder :: new ( )
108
93
. user_agent ( "Rust Playground - Top Crates Utility" )
@@ -148,9 +133,9 @@ impl TopCrates {
148
133
}
149
134
150
135
/// Add crates that have been hand-picked
151
- fn add_curated_crates ( & mut self ) {
136
+ fn add_curated_crates ( & mut self , modifications : & Modifications ) {
152
137
self . crates . extend ( {
153
- MODIFICATIONS
138
+ modifications
154
139
. additions
155
140
. iter ( )
156
141
. cloned ( )
@@ -234,7 +219,7 @@ fn playground_metadata_features(pkg: &Package) -> Option<(Vec<String>, bool)> {
234
219
}
235
220
}
236
221
237
- pub fn generate_info ( ) -> ( BTreeMap < String , DependencySpec > , Vec < CrateInformation > ) {
222
+ pub fn generate_info ( modifications : & Modifications ) -> ( BTreeMap < String , DependencySpec > , Vec < CrateInformation > ) {
238
223
// Setup to interact with cargo.
239
224
let config = Config :: default ( ) . expect ( "Unable to create default Cargo config" ) ;
240
225
let _lock = config. acquire_package_cache_lock ( ) ;
@@ -244,13 +229,13 @@ pub fn generate_info() -> (BTreeMap<String, DependencySpec>, Vec<CrateInformatio
244
229
245
230
let mut top = TopCrates :: download ( ) ;
246
231
top. add_rust_cookbook_crates ( ) ;
247
- top. add_curated_crates ( ) ;
232
+ top. add_curated_crates ( modifications ) ;
248
233
249
234
// Find the newest (non-prerelease, non-yanked) versions of all
250
235
// the interesting crates.
251
236
let mut summaries = Vec :: new ( ) ;
252
237
for Crate { name } in & top. crates {
253
- if MODIFICATIONS . excluded ( name) {
238
+ if modifications . excluded ( name) {
254
239
continue ;
255
240
}
256
241
@@ -326,7 +311,7 @@ pub fn generate_info() -> (BTreeMap<String, DependencySpec>, Vec<CrateInformatio
326
311
let package_ids: Vec < _ > = resolve
327
312
. iter ( )
328
313
. filter ( |pkg| valid_for_our_platform. contains ( pkg) )
329
- . filter ( |pkg| !MODIFICATIONS . excluded ( pkg. name ( ) . as_str ( ) ) )
314
+ . filter ( |pkg| !modifications . excluded ( pkg. name ( ) . as_str ( ) ) )
330
315
. collect ( ) ;
331
316
332
317
let mut sources = SourceMap :: new ( ) ;
0 commit comments