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