Struct version_check::Version [−][src]
pub struct Version(_);
Expand description
Version number: major.minor.patch
, ignoring release channel.
Implementations
Reads the version of the running compiler. If it cannot be determined
(see the top-level documentation), returns None
.
Example
use version_check::Version;
match Version::read() {
Some(d) => format!("Version is: {}", d),
None => format!("Failed to read the version.")
};
Parse a Rust release version (of the form
major[.minor[.patch[-channel]]]
), ignoring the release channel, if
any. Returns None
if version
is not a valid Rust version string.
Example
use version_check::Version;
let version = Version::parse("1.18.0").unwrap();
assert!(version.exactly("1.18.0"));
let version = Version::parse("1.20.0-nightly").unwrap();
assert!(version.exactly("1.20.0"));
assert!(version.exactly("1.20.0-beta"));
let version = Version::parse("1.3").unwrap();
assert!(version.exactly("1.3.0"));
let version = Version::parse("1").unwrap();
assert!(version.exactly("1.0.0"));
assert!(Version::parse("one.two.three").is_none());
assert!(Version::parse("1.65536.2").is_none());
assert!(Version::parse("1. 2").is_none());
assert!(Version::parse("").is_none());
assert!(Version::parse("1.").is_none());
assert!(Version::parse("1.2.3.4").is_none());
Creates a Version
from (major, minor, patch)
version components.
Example
use version_check::Version;
assert!(Version::from_mmp(1, 35, 0).exactly("1.35.0"));
assert!(Version::from_mmp(1, 33, 0).exactly("1.33.0"));
assert!(Version::from_mmp(1, 35, 1).exactly("1.35.1"));
assert!(Version::from_mmp(1, 13, 2).exactly("1.13.2"));
Returns the (major, minor, patch)
version components of self
.
Example
use version_check::Version;
assert_eq!(Version::parse("1.35.0").unwrap().to_mmp(), (1, 35, 0));
assert_eq!(Version::parse("1.33.0").unwrap().to_mmp(), (1, 33, 0));
assert_eq!(Version::parse("1.35.1").unwrap().to_mmp(), (1, 35, 1));
assert_eq!(Version::parse("1.13.2").unwrap().to_mmp(), (1, 13, 2));
Returns true
if self
is greater than or equal to version
.
If version
is greater than self
, or if version
is not a valid Rust
version string, returns false
.
Example
use version_check::Version;
let version = Version::parse("1.35.0").unwrap();
assert!(version.at_least("1.33.0"));
assert!(version.at_least("1.35.0"));
assert!(version.at_least("1.13.2"));
assert!(!version.at_least("1.35.1"));
assert!(!version.at_least("1.55.0"));
let version = Version::parse("1.12.5").unwrap();
assert!(version.at_least("1.12.0"));
assert!(!version.at_least("1.35.0"));
Returns true
if self
is less than or equal to version
.
If version
is less than self
, or if version
is not a valid Rust
version string, returns false
.
Example
use version_check::Version;
let version = Version::parse("1.35.0").unwrap();
assert!(version.at_most("1.35.1"));
assert!(version.at_most("1.55.0"));
assert!(version.at_most("1.35.0"));
assert!(!version.at_most("1.33.0"));
assert!(!version.at_most("1.13.2"));
Returns true
if self
is exactly equal to version
.
If version
is not equal to self
, or if version
is not a valid Rust
version string, returns false
.
Example
use version_check::Version;
let version = Version::parse("1.35.0").unwrap();
assert!(version.exactly("1.35.0"));
assert!(!version.exactly("1.33.0"));
assert!(!version.exactly("1.35.1"));
assert!(!version.exactly("1.13.2"));
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Version
impl UnwindSafe for Version
Blanket Implementations
Mutably borrows from an owned value. Read more