1
1
#![ deny( missing_docs) ]
2
-
3
2
// N.B. requires nightly rustdoc to document until intra-doc links are stabilized.
4
3
//! Collect information that allows you to build a crate the same way that docs.rs would.
5
4
//!
33
32
//! # }
34
33
//! ```
35
34
36
- use std:: collections:: { HashSet , HashMap } ;
35
+ use std:: collections:: { HashMap , HashSet } ;
37
36
use std:: io;
38
37
use std:: path:: Path ;
39
38
@@ -170,7 +169,7 @@ impl Metadata {
170
169
///
171
170
/// [`from_str`]: std::str::FromStr
172
171
pub fn from_manifest < P : AsRef < Path > > ( path : P ) -> Result < Metadata , MetadataError > {
173
- use std:: { str:: FromStr , fs } ;
172
+ use std:: { fs , str:: FromStr } ;
174
173
let buf = fs:: read_to_string ( path) ?;
175
174
Metadata :: from_str ( & buf) . map_err ( Into :: into)
176
175
}
@@ -234,9 +233,7 @@ impl Metadata {
234
233
235
234
/// Return the environment variables that should be set when building this crate.
236
235
pub fn environment_variables ( & self ) -> HashMap < & ' static str , String > {
237
- let joined = |v : & Option < Vec < _ > > | v. as_ref ( )
238
- . map ( |args| args. join ( " " ) )
239
- . unwrap_or_default ( ) ;
236
+ let joined = |v : & Option < Vec < _ > > | v. as_ref ( ) . map ( |args| args. join ( " " ) ) . unwrap_or_default ( ) ;
240
237
241
238
let mut map = HashMap :: new ( ) ;
242
239
map. insert ( "RUSTFLAGS" , joined ( & self . rustc_args ) ) ;
@@ -332,8 +329,8 @@ impl Default for Metadata {
332
329
333
330
#[ cfg( test) ]
334
331
mod test_parsing {
335
- use std:: str:: FromStr ;
336
332
use super :: * ;
333
+ use std:: str:: FromStr ;
337
334
338
335
#[ test]
339
336
fn test_cratesfyi_metadata ( ) {
@@ -402,7 +399,8 @@ mod test_parsing {
402
399
[package]
403
400
name = "test"
404
401
"# ,
405
- ) . unwrap ( ) ;
402
+ )
403
+ . unwrap ( ) ;
406
404
assert ! ( metadata. targets. is_none( ) ) ;
407
405
408
406
// targets explicitly set to empty array
@@ -411,7 +409,8 @@ mod test_parsing {
411
409
[package.metadata.docs.rs]
412
410
targets = []
413
411
"# ,
414
- ) . unwrap ( ) ;
412
+ )
413
+ . unwrap ( ) ;
415
414
assert ! ( metadata. targets. unwrap( ) . is_empty( ) ) ;
416
415
}
417
416
}
@@ -616,16 +615,42 @@ mod test_calculations {
616
615
617
616
// rustdocflags
618
617
let metadata = Metadata {
619
- rustdoc_args : Some ( vec ! [ "-Z" . into( ) , "unstable-options" . into( ) , "--static-root-path" . into( ) , "/" . into( ) , "--cap-lints" . into( ) , "warn" . into( ) ] ) ,
618
+ rustdoc_args : Some ( vec ! [
619
+ "-Z" . into( ) ,
620
+ "unstable-options" . into( ) ,
621
+ "--static-root-path" . into( ) ,
622
+ "/" . into( ) ,
623
+ "--cap-lints" . into( ) ,
624
+ "warn" . into( ) ,
625
+ ] ) ,
620
626
..Metadata :: default ( )
621
627
} ;
622
- assert_eq ! ( metadata. environment_variables( ) . get( "RUSTDOCFLAGS" ) . map( String :: as_str) , Some ( "-Z unstable-options --static-root-path / --cap-lints warn" ) ) ;
628
+ assert_eq ! (
629
+ metadata
630
+ . environment_variables( )
631
+ . get( "RUSTDOCFLAGS" )
632
+ . map( String :: as_str) ,
633
+ Some ( "-Z unstable-options --static-root-path / --cap-lints warn" )
634
+ ) ;
623
635
624
636
// rustdocflags
625
637
let metadata = Metadata {
626
- rustc_args : Some ( vec ! [ "-Z" . into( ) , "unstable-options" . into( ) , "--static-root-path" . into( ) , "/" . into( ) , "--cap-lints" . into( ) , "warn" . into( ) ] ) ,
638
+ rustc_args : Some ( vec ! [
639
+ "-Z" . into( ) ,
640
+ "unstable-options" . into( ) ,
641
+ "--static-root-path" . into( ) ,
642
+ "/" . into( ) ,
643
+ "--cap-lints" . into( ) ,
644
+ "warn" . into( ) ,
645
+ ] ) ,
627
646
..Metadata :: default ( )
628
647
} ;
629
- assert_eq ! ( metadata. environment_variables( ) . get( "RUSTFLAGS" ) . map( String :: as_str) , Some ( "-Z unstable-options --static-root-path / --cap-lints warn" ) ) ;
648
+ assert_eq ! (
649
+ metadata
650
+ . environment_variables( )
651
+ . get( "RUSTFLAGS" )
652
+ . map( String :: as_str) ,
653
+ Some ( "-Z unstable-options --static-root-path / --cap-lints warn" )
654
+ ) ;
630
655
}
631
656
}
0 commit comments