Enum clippy_utils::RustcVersion [−]
pub(crate) enum RustcVersion {
Normal(NormalVersion),
Special(SpecialVersion),
}Expand description
RustcVersion represents a version of the Rust Compiler.
This struct only supports the [NormalVersion] format
major.minor.patchand 3 special formats represented by the [SpecialVersion] enum.
A version can be created with one of the functions RustcVersion::new or
RustcVersion::parse. The RustcVersion::new method only supports the
normal version format.
You can compare two versions, just as you would expect:
use rustc_semver::RustcVersion;
assert!(RustcVersion::new(1, 34, 0) > RustcVersion::parse("1.10").unwrap());
assert!(RustcVersion::new(1, 34, 0) > RustcVersion::parse("0.9").unwrap());This comparison is semver conform according to the semver definition of
precedence. However, if you want to check whether one version meets
another version according to the Caret Requirements, you should use
RustcVersion::meets.
Variants
Normal(NormalVersion)
Special(SpecialVersion)
Implementations
impl RustcVersion
impl RustcVersion
pub const fn new(major: u32, minor: u32, patch: u32) -> RustcVersion
pub const fn new(major: u32, minor: u32, patch: u32) -> RustcVersion
RustcVersion::new is a const constructor for a RustcVersion.
This function is primarily used to construct constants, for everything
else use RustcVersion::parse.
This function only allows to construct normal versions. For special
versions, construct them directly with the [SpecialVersion] enum.
Examples
use rustc_semver::RustcVersion;
const MY_FAVORITE_RUST: RustcVersion = RustcVersion::new(1, 48, 0);
assert!(MY_FAVORITE_RUST > RustcVersion::new(1, 0, 0))pub fn parse(version: &str) -> Result<RustcVersion, Error>
pub fn parse(version: &str) -> Result<RustcVersion, Error>
RustcVersion::parse parses a RustcVersion.
This function can parse all normal and special versions. It is possbile
to omit parts of the version, like the patch or minor version part. So
1, 1.0, and 1.0.0 are all valid inputs and will result in the
same version.
Errors
This function returns an [Error], if the passed string is not a valid
RustcVersion
Examples
use rustc_semver::{SpecialVersion, RustcVersion};
let ver = RustcVersion::new(1, 0, 0);
assert_eq!(RustcVersion::parse("1").unwrap(), ver);
assert_eq!(RustcVersion::parse("1.0").unwrap(), ver);
assert_eq!(RustcVersion::parse("1.0.0").unwrap(), ver);
assert_eq!(
RustcVersion::parse("1.0.0-alpha").unwrap(),
RustcVersion::Special(SpecialVersion::Alpha)
);pub fn meets(self, other: RustcVersion) -> bool
pub fn meets(self, other: RustcVersion) -> bool
RustcVersion::meets implements a semver conform version check
according to the Caret Requirements.
Note that [SpecialVersion]s only meet themself and no other version
meets a [SpecialVersion]. This is because according to semver,
special versions are considered unstable and “might not satisfy the
intended compatibility requirements as denoted by [their] associated
normal version”.
Examples
use rustc_semver::RustcVersion;
assert!(RustcVersion::new(1, 30, 0).meets(RustcVersion::parse("1.29").unwrap()));
assert!(!RustcVersion::new(1, 30, 0).meets(RustcVersion::parse("1.31").unwrap()));
assert!(RustcVersion::new(0, 2, 1).meets(RustcVersion::parse("0.2").unwrap()));
assert!(!RustcVersion::new(0, 3, 0).meets(RustcVersion::parse("0.2").unwrap()));Trait Implementations
impl Clone for RustcVersion
impl Clone for RustcVersion
pub fn clone(&self) -> RustcVersion
pub fn clone(&self) -> RustcVersion
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
impl Debug for RustcVersion
impl Debug for RustcVersion
impl Display for RustcVersion
impl Display for RustcVersion
impl Ord for RustcVersion
impl Ord for RustcVersion
pub fn cmp(&self, other: &RustcVersion) -> Ordering
pub fn cmp(&self, other: &RustcVersion) -> Ordering
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
impl PartialEq<RustcVersion> for RustcVersion
impl PartialEq<RustcVersion> for RustcVersion
pub fn eq(&self, other: &RustcVersion) -> bool
pub fn eq(&self, other: &RustcVersion) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
pub fn ne(&self, other: &RustcVersion) -> bool
pub fn ne(&self, other: &RustcVersion) -> bool
This method tests for !=.
impl PartialOrd<RustcVersion> for RustcVersion
impl PartialOrd<RustcVersion> for RustcVersion
pub fn partial_cmp(&self, other: &RustcVersion) -> Option<Ordering>
pub fn partial_cmp(&self, other: &RustcVersion) -> Option<Ordering>
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
impl Copy for RustcVersion
impl Eq for RustcVersion
impl StructuralEq for RustcVersion
impl StructuralPartialEq for RustcVersion
Auto Trait Implementations
impl RefUnwindSafe for RustcVersion
impl Send for RustcVersion
impl Sync for RustcVersion
impl Unpin for RustcVersion
impl UnwindSafe for RustcVersion
Blanket Implementations
Mutably borrows from an owned value. Read more
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 20 bytes
Size for each variant:
Normal: 19 bytesSpecial: 1 byte