Struct cfg_rust_features::CfgRustFeatures
source · pub struct CfgRustFeatures { /* private fields */ }
Expand description
Information about the current Rust compiler.
Gathered when a new intance is created. Used to emit
conditional-compilation configuration-options for use with the cfg
et al
attributes.
Intended to be used from a package’s build script.
Implementations§
source§impl CfgRustFeatures
impl CfgRustFeatures
sourcepub fn emit<F: FeatureName, I: IntoIterator<Item = F>>(
features_names: I
) -> ResultDynErr<EnabledFeatures<F>>
pub fn emit<F: FeatureName, I: IntoIterator<Item = F>>( features_names: I ) -> ResultDynErr<EnabledFeatures<F>>
Convenience that calls Self::emit_multiple
on a temporary instance.
sourcepub fn new() -> ResultDynErr<Self>
pub fn new() -> ResultDynErr<Self>
Gather the information about the current Rust compiler, and return a new instance that can perform the operations with it.
Intended to be called from a package’s build script.
§Errors
If the information gathering fails. (E.g., if the OUT_DIR
environment variable is not
set, or if rustc
could not be run.)
sourcepub fn emit_multiple<F: FeatureName, I: IntoIterator<Item = F>>(
&self,
features_names: I
) -> Result<EnabledFeatures<F>, UnsupportedFeatureTodoError>
pub fn emit_multiple<F: FeatureName, I: IntoIterator<Item = F>>( &self, features_names: I ) -> Result<EnabledFeatures<F>, UnsupportedFeatureTodoError>
Write, to stdout
, instructions for Cargo to set configuration options that indicate
whether the currently-used version of Rust (compiler, language, and library) has enabled
the given sequence of features.
Intended to be called from a package’s build script.
The supported feature names are particular to this crate but do correspond to The
Unstable Book where
appropriate, but there are some extra feature names, like "unstable_features"
, that are
also supported.
Each feature’s configuration-option identifier has a naming scheme that categorizes
the feature according to whether it pertains to the compiler (rust_comp_feature
), the
language (rust_lang_feature
), or the standard library (rust_lib_feature
).
§Examples
let gathered_info_instance = try!(CfgRustFeatures::new());
let enabled_features = try!(gathered_info_instance.emit_multiple(vec![
"arbitrary_self_types",
"cfg_version",
"destructuring_assignment",
"error_in_core",
"inner_deref",
"iter_zip",
"never_type",
"question_mark",
"step_trait",
"unwrap_infallible",
"unstable_features",
]));
with rustc
version 1.0
, will write nothing to stdout
.
or, with rustc
version 1.56
, will write to stdout
:
cargo:rustc-cfg=rust_lang_feature="question_mark"
cargo:rustc-cfg=rust_lib_feature="inner_deref"
or, with rustc
version 1.59
, will write to stdout
:
cargo:rustc-cfg=rust_lang_feature="destructuring_assignment"
cargo:rustc-cfg=rust_lang_feature="question_mark"
cargo:rustc-cfg=rust_lib_feature="iter_zip"
cargo:rustc-cfg=rust_lib_feature="inner_deref"
or, with rustc
version 1.61.0-nightly
, will write to stdout
:
cargo:rustc-cfg=rust_comp_feature="unstable_features"
cargo:rustc-cfg=rust_lang_feature="destructuring_assignment"
cargo:rustc-cfg=rust_lang_feature="question_mark"
cargo:rustc-cfg=rust_lib_feature="inner_deref"
cargo:rustc-cfg=rust_lib_feature="iter_zip"
§Returns
A HashMap
that indicates whether each of the given features was found to be enabled
and its categories if so. May be ignored, since the instructions for Cargo are also
written out.
§Errors
If a feature name is unsupported by the current version of this crate. The message will show the URL where a new issue may be opened to request adding support for the feature.
Note: This crate’s stability policy allows for this error behavior to change somewhat: future versions having the same primary number may change to support additional feature names and so no longer error for those; but once a feature name is supported it will not be removed and so will never error for that and future versions.
sourcepub fn probe_multiple<F: FeatureName, I: IntoIterator<Item = F>>(
&self,
features_names: I
) -> Result<EnabledFeatures<F>, UnsupportedFeatureTodoError>
pub fn probe_multiple<F: FeatureName, I: IntoIterator<Item = F>>( &self, features_names: I ) -> Result<EnabledFeatures<F>, UnsupportedFeatureTodoError>
Like Self::emit_multiple
but does not write anything. Use when only the return value
is of interest.
§Returns
Same as Self::emit_multiple
.
§Errors
Same as Self::emit_multiple
.