[−][src]Enum rustc_semver::RustcVersion
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)
Special(SpecialVersion)
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 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
[src]
pub fn clone(&self) -> RustcVersion
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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]
pub fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<RustcVersion> for RustcVersion
[src]
pub fn eq(&self, other: &RustcVersion) -> bool
[src]
pub fn ne(&self, other: &RustcVersion) -> bool
[src]
impl PartialOrd<RustcVersion> for RustcVersion
[src]
pub fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,