Crate version_check[−][src]
Expand description
This tiny crate checks that the running or installed rustc meets some
version requirements. The version is queried by calling the Rust compiler
with --version. The path to the compiler is determined first via the
RUSTC environment variable. If it is not set, then rustc is used. If
that fails, no determination is made, and calls return None.
Examples
-
Set a
cfgflag inbuild.rsif the running compiler was determined to be at least version1.13.0:extern crate version_check as rustc; if rustc::is_min_version("1.13.0").unwrap_or(false) { println!("cargo:rustc-cfg=question_mark_operator"); }See
is_max_versionoris_exact_versionto check if the compiler is at most or exactly a certain version. -
Check that the running compiler was released on or after
2018-12-18:extern crate version_check as rustc; match rustc::is_min_date("2018-12-18") { Some(true) => "Yep! It's recent!", Some(false) => "No, it's older.", None => "Couldn't determine the rustc version." };See
is_max_dateoris_exact_dateto check if the compiler was released prior to or exactly on a certain date. -
Check that the running compiler supports feature flags:
extern crate version_check as rustc; match rustc::is_feature_flaggable() { Some(true) => "Yes! It's a dev or nightly release!", Some(false) => "No, it's stable or beta.", None => "Couldn't determine the rustc version." }; -
Check that the running compiler supports a specific feature:
extern crate version_check as rustc; if let Some(true) = rustc::supports_feature("doc_cfg") { println!("cargo:rustc-cfg=has_doc_cfg"); } -
Check that the running compiler is on the stable channel:
extern crate version_check as rustc; match rustc::Channel::read() { Some(c) if c.is_stable() => format!("Yes! It's stable."), Some(c) => format!("No, the channel {} is not stable.", c), None => format!("Couldn't determine the rustc version.") };
To interact with the version, release date, and release channel as structs,
use Version, Date, and Channel, respectively. The triple()
function returns all three values efficiently.
Alternatives
This crate is dead simple with no dependencies. If you need something more and don’t care about panicking if the version cannot be obtained, or if you don’t mind adding dependencies, see rustc_version.
Structs
Release channel: “dev”, “nightly”, “beta”, or “stable”.
Release date including year, month, and day.
Version number: major.minor.patch, ignoring release channel.
Functions
Checks that the running or installed rustc was released exactly on
some date.
Checks that the running or installed rustc is exactly some version.
Checks whether the running or installed rustc supports feature flags.
Checks that the running or installed rustc was released on or before
some date.
Checks that the running or installed rustc is at most some maximum
version.
Checks that the running or installed rustc was released on or after
some date.
Checks that the running or installed rustc is at least some minimum
version.
Checks whether the running or installed rustc supports feature.
