@@ -197,12 +197,12 @@ mod cfg {
197
197
/// Disambiguation of the [target ABI](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_abi)
198
198
/// when the [target env](cargo_cfg_target_env) isn't sufficient.
199
199
///
200
- /// For historical reasons, this value is only defined as not the empty-string when
200
+ /// For historical reasons, this value is only defined as `Some` when
201
201
/// actually needed for disambiguation. Thus, for example, on many GNU platforms,
202
- /// this value will be empty .
202
+ /// this value will be `None` .
203
203
#[ track_caller]
204
- pub fn cargo_cfg_target_abi ( ) -> String {
205
- to_string ( var_or_panic ( "CARGO_CFG_TARGET_ABI" ) )
204
+ pub fn cargo_cfg_target_abi ( ) -> Option < String > {
205
+ to_opt ( var_or_panic ( "CARGO_CFG_TARGET_ABI" ) ) . map ( to_string )
206
206
}
207
207
208
208
/// The CPU [target architecture](https://doc.rust-lang.org/stable/reference/conditional-compilation.html#target_arch).
@@ -480,8 +480,8 @@ pub fn cargo_pkg_version_patch() -> u64 {
480
480
481
481
/// The pre-release version of your package.
482
482
#[ track_caller]
483
- pub fn cargo_pkg_version_pre ( ) -> String {
484
- to_string ( var_or_panic ( "CARGO_PKG_VERSION_PRE" ) )
483
+ pub fn cargo_pkg_version_pre ( ) -> Option < String > {
484
+ to_opt ( var_or_panic ( "CARGO_PKG_VERSION_PRE" ) ) . map ( to_string )
485
485
}
486
486
487
487
/// Colon separated list of authors from the manifest of your package.
@@ -498,45 +498,45 @@ pub fn cargo_pkg_name() -> String {
498
498
499
499
/// The description from the manifest of your package.
500
500
#[ track_caller]
501
- pub fn cargo_pkg_description ( ) -> String {
502
- to_string ( var_or_panic ( "CARGO_PKG_DESCRIPTION" ) )
501
+ pub fn cargo_pkg_description ( ) -> Option < String > {
502
+ to_opt ( var_or_panic ( "CARGO_PKG_DESCRIPTION" ) ) . map ( to_string )
503
503
}
504
504
505
505
/// The home page from the manifest of your package.
506
506
#[ track_caller]
507
- pub fn cargo_pkg_homepage ( ) -> String {
508
- to_string ( var_or_panic ( "CARGO_PKG_HOMEPAGE" ) )
507
+ pub fn cargo_pkg_homepage ( ) -> Option < String > {
508
+ to_opt ( var_or_panic ( "CARGO_PKG_HOMEPAGE" ) ) . map ( to_string )
509
509
}
510
510
511
511
/// The repository from the manifest of your package.
512
512
#[ track_caller]
513
- pub fn cargo_pkg_repository ( ) -> String {
514
- to_string ( var_or_panic ( "CARGO_PKG_REPOSITORY" ) )
513
+ pub fn cargo_pkg_repository ( ) -> Option < String > {
514
+ to_opt ( var_or_panic ( "CARGO_PKG_REPOSITORY" ) ) . map ( to_string )
515
515
}
516
516
517
517
/// The license from the manifest of your package.
518
518
#[ track_caller]
519
- pub fn cargo_pkg_license ( ) -> String {
520
- to_string ( var_or_panic ( "CARGO_PKG_LICENSE" ) )
519
+ pub fn cargo_pkg_license ( ) -> Option < String > {
520
+ to_opt ( var_or_panic ( "CARGO_PKG_LICENSE" ) ) . map ( to_string )
521
521
}
522
522
523
523
/// The license file from the manifest of your package.
524
524
#[ track_caller]
525
- pub fn cargo_pkg_license_file ( ) -> PathBuf {
526
- to_path ( var_or_panic ( "CARGO_PKG_LICENSE_FILE" ) )
525
+ pub fn cargo_pkg_license_file ( ) -> Option < PathBuf > {
526
+ to_opt ( var_or_panic ( "CARGO_PKG_LICENSE_FILE" ) ) . map ( to_path )
527
527
}
528
528
529
529
/// The Rust version from the manifest of your package. Note that this is the
530
530
/// minimum Rust version supported by the package, not the current Rust version.
531
531
#[ track_caller]
532
- pub fn cargo_pkg_rust_version ( ) -> String {
533
- to_string ( var_or_panic ( "CARGO_PKG_RUST_VERSION" ) )
532
+ pub fn cargo_pkg_rust_version ( ) -> Option < String > {
533
+ to_opt ( var_or_panic ( "CARGO_PKG_RUST_VERSION" ) ) . map ( to_string )
534
534
}
535
535
536
536
/// Path to the README file of your package.
537
537
#[ track_caller]
538
- pub fn cargo_pkg_readme ( ) -> PathBuf {
539
- to_path ( var_or_panic ( "CARGO_PKG_README" ) )
538
+ pub fn cargo_pkg_readme ( ) -> Option < PathBuf > {
539
+ to_opt ( var_or_panic ( "CARGO_PKG_README" ) ) . map ( to_path )
540
540
}
541
541
542
542
fn is_present ( key : & str ) -> bool {
@@ -563,8 +563,15 @@ fn to_string(value: std::ffi::OsString) -> String {
563
563
}
564
564
}
565
565
566
+ fn to_opt ( value : std:: ffi:: OsString ) -> Option < std:: ffi:: OsString > {
567
+ ( !value. is_empty ( ) ) . then_some ( value)
568
+ }
569
+
566
570
#[ track_caller]
567
571
fn to_strings ( value : std:: ffi:: OsString , sep : char ) -> Vec < String > {
572
+ if value. is_empty ( ) {
573
+ return Vec :: new ( ) ;
574
+ }
568
575
let value = to_string ( value) ;
569
576
value. split ( sep) . map ( str:: to_owned) . collect ( )
570
577
}
0 commit comments