pub 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)
Special(SpecialVersion)
Implementations§
Source§impl RustcVersion
impl RustcVersion
Sourcepub const fn new(major: u32, minor: u32, patch: u32) -> Self
pub const fn new(major: u32, minor: u32, patch: u32) -> Self
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))
Sourcepub fn parse(version: &str) -> Result<Self>
pub fn parse(version: &str) -> Result<Self>
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)
);
Sourcepub fn meets(self, other: Self) -> bool
pub fn meets(self, other: Self) -> 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§
Source§impl Clone for RustcVersion
impl Clone for RustcVersion
Source§fn clone(&self) -> RustcVersion
fn clone(&self) -> RustcVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RustcVersion
impl Debug for RustcVersion
Source§impl Display for RustcVersion
impl Display for RustcVersion
Source§impl Ord for RustcVersion
impl Ord for RustcVersion
Source§impl PartialEq for RustcVersion
impl PartialEq for RustcVersion
Source§impl PartialOrd for RustcVersion
impl PartialOrd for RustcVersion
impl Copy for RustcVersion
impl Eq for RustcVersion
impl StructuralPartialEq for RustcVersion
Auto Trait Implementations§
impl Freeze for RustcVersion
impl RefUnwindSafe for RustcVersion
impl Send for RustcVersion
impl Sync for RustcVersion
impl Unpin for RustcVersion
impl UnwindSafe for RustcVersion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)