Skip to main content

cargo_msrv/rust/
release.rs

1use crate::rust::Toolchain;
2
3/// A `cargo-msrv` Rust release.
4///
5// FIXME: The next rust-releases version will also contain target information.
6// FIXME: There should be a difference between the available releases, and the requested set of (toolchain, target, component)'s.
7//        Only the "Release" part of this struct has been sourced from some Rust release channel, the target and components have been added later
8//        but are really items which we want to have; they may not exist. This can be a bit confusing when running cargo msrv with with debug logs on.
9#[derive(Clone, Debug, PartialEq)]
10pub struct RustRelease {
11    release: rust_releases::Release,
12    target: &'static str,
13    components: &'static [&'static str],
14}
15
16impl RustRelease {
17    pub fn new(
18        release: rust_releases::Release,
19        target: &'static str,
20        components: &'static [&'static str],
21    ) -> Self {
22        Self {
23            release,
24            target,
25            components,
26        }
27    }
28
29    /// Get the [`Toolchain`] for the given Rust release.
30    pub fn to_toolchain_spec(&self) -> Toolchain {
31        let version = self.release.version();
32        Toolchain::new(version.clone(), self.target, self.components)
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use crate::rust::RustRelease;
39    use crate::rust::Toolchain;
40    use rust_releases::semver;
41
42    #[test]
43    fn spec() {
44        let version = semver::Version::new(1, 2, 3);
45        let rust_release = RustRelease::new(
46            rust_releases::Release::new_stable(version.clone()),
47            "x",
48            &[],
49        );
50        let spec = rust_release.to_toolchain_spec();
51
52        let expected = Toolchain::new(version, "x", &[]);
53        assert_eq!(spec, expected);
54    }
55}