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

source

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.

source

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.)

source

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.

source

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.

Trait Implementations§

source§

impl Debug for CfgRustFeatures

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.