Name Description Size
channel.rs 5425
date.rs 6198
lib.rs 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 `cfg` flag in `build.rs` if the running compiler was determined to be at least version `1.13.0`: ```rust 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_version`] or [`is_exact_version`] to 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`: ```rust 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_date`] or [`is_exact_date`] to check if the compiler was released _prior to_ or _exactly on_ a certain date. * Check that the running compiler supports feature flags: ```rust 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: ```rust 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: ```rust 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](https://crates.io/crates/rustc_version). 19153
version.rs 10435