@@ -13,11 +13,9 @@ use cargo::{
1313 util:: Config ,
1414} ;
1515use itertools:: Itertools ;
16- use lazy_static:: lazy_static;
1716use serde:: { Deserialize , Serialize } ;
1817use std:: {
1918 collections:: { BTreeMap , BTreeSet , HashSet } ,
20- fs:: File ,
2119 io:: Read ,
2220} ;
2321
@@ -52,12 +50,12 @@ pub struct CrateInformation {
5250}
5351
5452/// Hand-curated changes to the crate list
55- #[ derive( Debug , Deserialize ) ]
56- struct Modifications {
53+ #[ derive( Debug , Default , Deserialize ) ]
54+ pub struct Modifications {
5755 #[ serde( default ) ]
58- exclusions : Vec < String > ,
56+ pub exclusions : Vec < String > ,
5957 #[ serde( default ) ]
60- additions : BTreeSet < String > ,
58+ pub additions : BTreeSet < String > ,
6159}
6260
6361#[ derive( Debug , Serialize , Clone ) ]
@@ -90,19 +88,6 @@ impl Modifications {
9088 }
9189}
9290
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-
10691fn simple_get ( url : & str ) -> reqwest:: Result < reqwest:: blocking:: Response > {
10792 reqwest:: blocking:: ClientBuilder :: new ( )
10893 . user_agent ( "Rust Playground - Top Crates Utility" )
@@ -148,9 +133,9 @@ impl TopCrates {
148133 }
149134
150135 /// Add crates that have been hand-picked
151- fn add_curated_crates ( & mut self ) {
136+ fn add_curated_crates ( & mut self , modifications : & Modifications ) {
152137 self . crates . extend ( {
153- MODIFICATIONS
138+ modifications
154139 . additions
155140 . iter ( )
156141 . cloned ( )
@@ -234,7 +219,7 @@ fn playground_metadata_features(pkg: &Package) -> Option<(Vec<String>, bool)> {
234219 }
235220}
236221
237- pub fn generate_info ( ) -> ( BTreeMap < String , DependencySpec > , Vec < CrateInformation > ) {
222+ pub fn generate_info ( modifications : & Modifications ) -> ( BTreeMap < String , DependencySpec > , Vec < CrateInformation > ) {
238223 // Setup to interact with cargo.
239224 let config = Config :: default ( ) . expect ( "Unable to create default Cargo config" ) ;
240225 let _lock = config. acquire_package_cache_lock ( ) ;
@@ -244,13 +229,13 @@ pub fn generate_info() -> (BTreeMap<String, DependencySpec>, Vec<CrateInformatio
244229
245230 let mut top = TopCrates :: download ( ) ;
246231 top. add_rust_cookbook_crates ( ) ;
247- top. add_curated_crates ( ) ;
232+ top. add_curated_crates ( modifications ) ;
248233
249234 // Find the newest (non-prerelease, non-yanked) versions of all
250235 // the interesting crates.
251236 let mut summaries = Vec :: new ( ) ;
252237 for Crate { name } in & top. crates {
253- if MODIFICATIONS . excluded ( name) {
238+ if modifications . excluded ( name) {
254239 continue ;
255240 }
256241
@@ -326,7 +311,7 @@ pub fn generate_info() -> (BTreeMap<String, DependencySpec>, Vec<CrateInformatio
326311 let package_ids: Vec < _ > = resolve
327312 . iter ( )
328313 . 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 ( ) ) )
330315 . collect ( ) ;
331316
332317 let mut sources = SourceMap :: new ( ) ;
0 commit comments