#![warn(clippy::all)]
#![deny(missing_docs)]
#![deny(unsafe_code)]
pub use rust_toolchain::channel::{Beta, Nightly, Stable};
use std::cmp;
use std::fmt::Debug;
pub mod date {
pub use rust_toolchain::Date;
}
pub mod toolchain {
pub use rust_toolchain::{Channel, Component, RustVersion, Target, Toolchain};
}
pub mod version;
#[derive(Clone, Debug)]
pub struct RustRelease<V: Debug, C = ()> {
pub version: V,
pub release_date: Option<date::Date>,
pub toolchains: Vec<toolchain::Toolchain>,
pub context: C, }
impl<V: PartialEq + Debug, C> PartialEq for RustRelease<V, C> {
fn eq(&self, other: &Self) -> bool {
self.version.eq(&other.version)
}
}
impl<V: Eq + Debug, C> Eq for RustRelease<V, C> {}
impl<V: PartialOrd + Debug, C> PartialOrd for RustRelease<V, C> {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.version.partial_cmp(&other.version)
}
}
impl<V: Ord + Debug, C> Ord for RustRelease<V, C> {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.version.cmp(&other.version)
}
}
impl<V: Debug> RustRelease<V, ()> {
pub fn new(
version: V,
release_date: Option<rust_toolchain::Date>,
toolchains: impl IntoIterator<Item = toolchain::Toolchain>,
) -> Self {
Self {
version,
release_date,
toolchains: toolchains.into_iter().collect(),
context: (),
}
}
}
impl<V: Debug, C> RustRelease<V, C> {
pub fn version(&self) -> &V {
&self.version
}
pub fn release_date(&self) -> Option<&date::Date> {
self.release_date.as_ref()
}
pub fn toolchains(&self) -> impl Iterator<Item = &toolchain::Toolchain> {
self.toolchains.iter()
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ReleaseVersion {
Stable(Stable),
Beta(Beta),
Nightly(Nightly),
}
#[cfg(test)]
mod tests {
use super::*;
use crate::toolchain::Toolchain;
use rust_toolchain::RustVersion;
use std::collections::HashSet;
fn fake(stable: Stable, date: Option<rust_toolchain::Date>) -> Toolchain {
Toolchain::new(
rust_toolchain::Channel::Stable(stable),
date,
rust_toolchain::Target::host(),
HashSet::new(),
HashSet::new(),
)
}
#[test]
fn can_instantiate() {
let stable = Stable {
version: RustVersion::new(1, 82, 0),
};
let version = ReleaseVersion::Stable(stable.clone());
let release = RustRelease::new(version, None, vec![fake(stable.clone(), None)]);
assert_eq!(release.version(), &ReleaseVersion::Stable(stable));
}
#[yare::parameterized(
some = { Some(rust_toolchain::Date::new(2024, 1, 1)) },
none = { None },
)]
fn can_instantiate_deux(date: Option<rust_toolchain::Date>) {
let stable = Stable {
version: RustVersion::new(1, 82, 0),
};
let version = ReleaseVersion::Stable(stable.clone());
let release = RustRelease::new(version, date.clone(), vec![fake(stable, date)]);
let target_date = release.toolchains().next().unwrap().date();
assert_eq!(release.release_date(), target_date);
}
}