Skip to main content

rust_toolchain/channel/
stable.rs

1use crate::RustVersion;
2
3/// The `Stable` release [`channel`]
4///
5/// [`channel`]: https://rust-lang.github.io/rustup/concepts/channels.html
6#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
7pub struct Stable {
8    /// The three component Rust version
9    pub version: RustVersion,
10}
11
12impl Stable {
13    /// Instantiate a new `Stable` struct, representing the version of a release channel.
14    pub fn new(major: u64, minor: u64, patch: u64) -> Self {
15        Self {
16            version: RustVersion::new(major, minor, patch),
17        }
18    }
19}
20
21impl From<RustVersion> for Stable {
22    fn from(version: RustVersion) -> Self {
23        Self { version }
24    }
25}
26
27impl From<(u64, u64, u64)> for Stable {
28    fn from((major, minor, patch): (u64, u64, u64)) -> Self {
29        Self::new(major, minor, patch)
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use crate::{channel::Stable, RustVersion};
36
37    #[yare::parameterized(
38        patch1 = { RustVersion::new(0, 0, 0), RustVersion::new(0, 0, 1) },
39        minor1 = { RustVersion::new(0, 0, 0), RustVersion::new(0, 1, 0) },
40        major1 = { RustVersion::new(0, 0, 0), RustVersion::new(1, 0, 0) },
41        minor_over_patch = { RustVersion::new(0, 0, 999), RustVersion::new(0, 1, 0) },
42        major_over_patch = { RustVersion::new(0, 0, 999), RustVersion::new(1, 0, 0) },
43        major_over_minor = { RustVersion::new(0, 999, 0), RustVersion::new(1, 0, 0) },
44    )]
45    fn ord(left: RustVersion, right: RustVersion) {
46        let left = Stable { version: left };
47        let right = Stable { version: right };
48
49        assert!(left < right);
50    }
51}