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
impl RustVersion
Sourcepub const CURRENT: Self = crate::RUST_VERSION
pub const CURRENT: Self = crate::RUST_VERSION
The current rust version.
This is an alias for rustversion_detect::RUST_VERSION
.
Sourcepub const fn stable(major: u32, minor: u32, patch: u32) -> RustVersion
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.
Sourcepub const fn is_since_minor_version(&self, major: u32, minor: u32) -> bool
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));
Sourcepub const fn is_since_patch_version(
&self,
major: u32,
minor: u32,
patch: u32,
) -> bool
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));
Sourcepub const fn is_since_stable(&self, spec: StableVersionSpec) -> bool
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)))
Sourcepub const fn is_before_stable(&self, spec: StableVersionSpec) -> bool
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)]
Sourcepub const fn is_before_minor_version(&self, major: u32, minor: u32) -> bool
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.
Sourcepub const fn is_before_patch_version(
&self,
major: u32,
minor: u32,
patch: u32,
) -> bool
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.
Sourcepub const fn is_since(&self, spec: StableVersionSpec) -> bool
👎Deprecated: Please use is_since_stable
or the helper methods
pub const fn is_since(&self, spec: StableVersionSpec) -> bool
is_since_stable
or the helper methodsOld name of Self::is_since_stable
.
Deprecated due to unclear naming and preference for
helper methods Self::is_since_minor_version
.
Sourcepub const fn is_before(&self, spec: StableVersionSpec) -> bool
👎Deprecated: Please use is_before_stable
or the helper methods
pub const fn is_before(&self, spec: StableVersionSpec) -> bool
is_before_stable
or the helper methodsOld name of Self::is_before_stable
Deprecated due to unclear naming and preference for
helper methods like Self::is_before_minor_version
.
Sourcepub const fn is_since_nightly(&self, start: Date) -> bool
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
.
Sourcepub const fn is_before_nightly(&self, start: Date) -> bool
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
.
Sourcepub const fn is_nightly(&self) -> bool
pub const fn is_nightly(&self) -> bool
Check if a nightly compiler version is used.
Sourcepub const fn is_development(&self) -> bool
pub const fn is_development(&self) -> bool
Check if a development compiler version is used
Trait Implementations§
Source§impl Clone for RustVersion
impl Clone for RustVersion
Source§fn clone(&self) -> RustVersion
fn clone(&self) -> RustVersion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RustVersion
impl Debug for RustVersion
Source§impl Display for RustVersion
Displays the version in a manner similar to rustc --version
.
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.