1#![warn(clippy::all)]
15#![deny(missing_docs)]
16#![deny(unsafe_code)]
17
18pub use rust_toolchain::channel::{Beta, Nightly, Stable};
20use std::cmp;
21use std::fmt::Debug;
22
23pub mod date {
27 pub use rust_toolchain::Date;
28}
29pub mod toolchain {
31 pub use rust_toolchain::{Channel, Component, RustVersion, Target, Toolchain};
32}
33
34pub mod version;
36
37#[derive(Clone, Debug)]
45pub struct RustRelease<V: Debug, C = ()> {
46 pub version: V,
55 pub release_date: Option<date::Date>,
59 pub toolchains: Vec<toolchain::Toolchain>,
63 pub context: C, }
66
67impl<V: PartialEq + Debug, C> PartialEq for RustRelease<V, C> {
68 fn eq(&self, other: &Self) -> bool {
69 self.version.eq(&other.version)
70 }
71}
72
73impl<V: Eq + Debug, C> Eq for RustRelease<V, C> {}
74
75impl<V: PartialOrd + Debug, C> PartialOrd for RustRelease<V, C> {
76 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
77 self.version.partial_cmp(&other.version)
78 }
79}
80
81impl<V: Ord + Debug, C> Ord for RustRelease<V, C> {
82 fn cmp(&self, other: &Self) -> cmp::Ordering {
83 self.version.cmp(&other.version)
84 }
85}
86
87impl<V: Debug> RustRelease<V, ()> {
88 pub fn new(
91 version: V,
92 release_date: Option<rust_toolchain::Date>,
93 toolchains: impl IntoIterator<Item = toolchain::Toolchain>,
94 ) -> Self {
95 Self {
96 version,
97 release_date,
98 toolchains: toolchains.into_iter().collect(),
99 context: (),
100 }
101 }
102}
103
104impl<V: Debug, C> RustRelease<V, C> {
105 pub fn version(&self) -> &V {
109 &self.version
110 }
111
112 pub fn release_date(&self) -> Option<&date::Date> {
114 self.release_date.as_ref()
115 }
116
117 pub fn toolchains(&self) -> impl Iterator<Item = &toolchain::Toolchain> {
119 self.toolchains.iter()
120 }
121}
122
123#[derive(Clone, Debug, Eq, PartialEq)]
128pub enum ReleaseVersion {
129 Stable(Stable),
131 Beta(Beta),
133 Nightly(Nightly),
135}
136
137#[cfg(test)]
138mod tests {
139 use super::*;
140 use crate::toolchain::Toolchain;
141 use rust_toolchain::RustVersion;
142 use std::collections::HashSet;
143
144 fn fake(stable: Stable, date: Option<rust_toolchain::Date>) -> Toolchain {
145 Toolchain::new(
146 rust_toolchain::Channel::Stable(stable),
147 date,
148 rust_toolchain::Target::host(),
149 HashSet::new(),
150 HashSet::new(),
151 )
152 }
153
154 #[test]
155 fn can_instantiate() {
156 let stable = Stable {
157 version: RustVersion::new(1, 82, 0),
158 };
159 let version = ReleaseVersion::Stable(stable.clone());
160 let release = RustRelease::new(version, None, vec![fake(stable.clone(), None)]);
161
162 assert_eq!(release.version(), &ReleaseVersion::Stable(stable));
163 }
164
165 #[yare::parameterized(
166 some = { Some(rust_toolchain::Date::new(2024, 1, 1)) },
167 none = { None },
168 )]
169 fn can_instantiate_deux(date: Option<rust_toolchain::Date>) {
170 let stable = Stable {
171 version: RustVersion::new(1, 82, 0),
172 };
173 let version = ReleaseVersion::Stable(stable.clone());
174 let release = RustRelease::new(version, date.clone(), vec![fake(stable, date)]);
175
176 let target_date = release.toolchains().next().unwrap().date();
177
178 assert_eq!(release.release_date(), target_date);
179 }
180}