Struct RustVersion

Source
pub struct RustVersion {
    pub major: u32,
    pub minor: u32,
    pub patch: u32,
    pub channel: Channel,
}
Expand description

Indicates the rust version.

Fields§

§major: u32

The major version.

Should always be one.

§minor: u32

The minor version of rust.

§patch: u32

The patch version of the rust compiler.

§channel: Channel

The channel of the rust compiler.

Implementations§

Source§

impl RustVersion

Source

pub const CURRENT: Self = crate::RUST_VERSION

The current rust version.

This is an alias for rustversion_detect::RUST_VERSION.

Source

pub const fn stable(major: u32, minor: u32, patch: u32) -> RustVersion

Create a stable version with the specified combination of major, minor, and patch.

The major version must be 1.0.

Source

pub const fn is_since_minor_version(&self, major: u32, minor: u32) -> bool

Check if this version is after the specified stable minor version.

The patch version is unspecified and will be ignored.

This is a shorthand for calling Self::is_since_stable with a minor version spec created with StableVersionSpec::minor.

The major version must always be one, or a panic could happen.

§Example

assert!(RustVersion::stable(1, 32, 2).is_since_minor_version(1, 32));
assert!(RustVersion::stable(1, 48, 0).is_since_minor_version(1, 40));
Source

pub const fn is_since_patch_version( &self, major: u32, minor: u32, patch: u32, ) -> bool

Check if this version is after the specified stable patch version.

This is a shorthand for calling Self::is_since_stable with a patch version spec created with StableVersionSpec::patch.

The major version must always be one, or a panic could happen.

§Example

assert!(RustVersion::stable(1, 32, 2).is_since_patch_version(1, 32, 1));
assert!(RustVersion::stable(1, 48, 0).is_since_patch_version(1, 40, 5));
Source

pub const fn is_since_stable(&self, spec: StableVersionSpec) -> bool

Check if this version is after the given stable version spec.

In general, the Self::is_since_minor_version and Self::is_since_patch_version helper methods are preferable.

This ignores the channel.

The negation of Self::is_before_stable.

Behavior is (mostly) equivalent to #[rustversion::since($spec)]

§Example

assert!(RustVersion::stable(1, 32, 2).is_since_stable(StableVersionSpec::minor(1, 32)));
assert!(RustVersion::stable(1, 48, 0).is_since_stable(StableVersionSpec::patch(1, 32, 7)))
Source

pub const fn is_before_stable(&self, spec: StableVersionSpec) -> bool

Check if the version is less than the given stable version spec.

This ignores the channel.

In general, the Self::is_before_minor_version and Self::is_before_patch_version helper methods are preferable.

The negation of Self::is_since_stable.

Behavior is (mostly) equivalent to #[rustversion::before($spec)]

Source

pub const fn is_before_minor_version(&self, major: u32, minor: u32) -> bool

Check if this version is before the specified stable minor version.

The patch version is unspecified and will be ignored.

This is a shorthand for calling Self::is_before_stable with a minor version spec created with StableVersionSpec::minor.

The major version must always be one, or a panic could happen.

Source

pub const fn is_before_patch_version( &self, major: u32, minor: u32, patch: u32, ) -> bool

Check if this version is before the specified stable patch version.

This is a shorthand for calling Self::is_before_stable with a patch version spec created with StableVersionSpec::patch.

The major version must always be one, or a panic could happen.

Source

pub const fn is_since(&self, spec: StableVersionSpec) -> bool

👎Deprecated: Please use is_since_stable or the helper methods

Old name of Self::is_since_stable.

Deprecated due to unclear naming and preference for helper methods Self::is_since_minor_version.

Source

pub const fn is_before(&self, spec: StableVersionSpec) -> bool

👎Deprecated: Please use is_before_stable or the helper methods

Old name of Self::is_before_stable

Deprecated due to unclear naming and preference for helper methods like Self::is_before_minor_version.

Source

pub const fn is_since_nightly(&self, start: Date) -> bool

If this version is a nightly version after the specified start date.

Stable and beta versions are always considered before every nightly versions. Development versions are considered after every nightly version.

The negation of Self::is_before_nightly.

Behavior is (mostly) equivalent to #[rustversion::since($date)]

See also Date::is_since.

Source

pub const fn is_before_nightly(&self, start: Date) -> bool

If this version comes before the nightly version with the specified start date.

Stable and beta versions are always considered before every nightly versions. Development versions are considered after every nightly version.

The negation of Self::is_since_nightly.

See also Date::is_before.

Source

pub const fn is_nightly(&self) -> bool

Check if a nightly compiler version is used.

Source

pub const fn is_stable(&self) -> bool

Check if a stable compiler version is used

Source

pub const fn is_beta(&self) -> bool

Check if a beta compiler version is used

Source

pub const fn is_development(&self) -> bool

Check if a development compiler version is used

Trait Implementations§

Source§

impl Clone for RustVersion

Source§

fn clone(&self) -> RustVersion

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RustVersion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RustVersion

Displays the version in a manner similar to rustc --version.

The format here is not stable and may change in the future.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<StableVersionSpec> for RustVersion

Source§

fn from(value: StableVersionSpec) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for RustVersion

Source§

fn eq(&self, other: &RustVersion) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for RustVersion

Source§

impl Eq for RustVersion

Source§

impl StructuralPartialEq for RustVersion

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.