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.patch

and 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)

Tuple Fields

0: NormalVersion

Special(SpecialVersion)

Tuple Fields

0: SpecialVersion

Implementations

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))

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)
);

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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: