[][src]Enum rustc_semver::RustcVersion

pub enum RustcVersion {
    Normal(NormalVersion),
    Special(SpecialVersion),
}

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

Implementations

impl RustcVersion[src]

pub const fn new(major: u32, minor: u32, patch: u32) -> Self[src]

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<Self>[src]

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: Self) -> bool[src]

RustcVersion::meets implements a semver conform version check according to the Caret Requirements.

Note that SpecialVersions 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[src]

impl Copy for RustcVersion[src]

impl Debug for RustcVersion[src]

impl Display for RustcVersion[src]

impl Eq for RustcVersion[src]

impl Ord for RustcVersion[src]

impl PartialEq<RustcVersion> for RustcVersion[src]

impl PartialOrd<RustcVersion> for RustcVersion[src]

impl StructuralEq for RustcVersion[src]

impl StructuralPartialEq for RustcVersion[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.