Go to file
Sergio Benitez 96f94b7fc1 Parse only the last line of 'rustc --version'.
Cargo sometimes emits a 'warning' line to 'stdout', breaking the
canonical 'rustc --version' output, and thus breaking the parser. This
commit ignores everything but the last line of output from the command,
circumventing this issue.

Resolves #4.
2018-09-23 12:41:52 -07:00
src Parse only the last line of 'rustc --version'. 2018-09-23 12:41:52 -07:00
.gitignore Initial commit. 2017-01-15 00:46:39 -08:00
Cargo.toml New version: 0.1.4. 2018-07-05 12:53:04 -07:00
LICENSE-APACHE Relicense under dual MIT/Apache-2. 2018-07-05 12:49:43 -07:00
LICENSE-MIT Relicense under dual MIT/Apache-2. 2018-07-05 12:49:43 -07:00
README.md Relicense under dual MIT/Apache-2. 2018-07-05 12:49:43 -07:00

version_check

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.

Usage

Add to your Cargo.toml file, typically as a build dependency:

[build-dependencies]
version_check = "0.1"

Examples

Check that the running compiler is a nightly release:

extern crate version_check;

match version_check::is_nightly() {
    Some(true) => "running a nightly",
    Some(false) => "not nightly",
    None => "couldn't figure it out"
};

Check that the running compiler is at least version 1.13.0:

extern crate version_check;

match version_check::is_min_version("1.13.0") {
    Some((true, version)) => format!("Yes! It's: {}", version),
    Some((false, version)) => format!("No! {} is too old!", version),
    None => "couldn't figure it out".into()
};

Check that the running compiler was released on or after 2016-12-18:

extern crate version_check;

match version_check::is_min_date("2016-12-18") {
    Some((true, date)) => format!("Yes! It's: {}", date),
    Some((false, date)) => format!("No! {} is too long ago!", date),
    None => "couldn't figure it out".into()
};

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 adding dependencies, see rustc_version.

License

version_check is licensed under either of the following, at your option: