Skip to content

Commit ae08f3a

Browse files
committed
WIP
1 parent da185b8 commit ae08f3a

File tree

22 files changed

+713
-326
lines changed

22 files changed

+713
-326
lines changed

Cargo.toml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,37 @@ exclude = [
1818

1919
[workspace]
2020
members = [
21+
# extra
2122
"crates/rust-release",
23+
"crates/rust-toolchain",
24+
# core & shared impl
2225
"crates/rust-releases-core",
2326
"crates/rust-releases-io",
27+
# sources
28+
"crates/rust-releases-github",
2429
"crates/rust-releases-rust-changelog",
2530
"crates/rust-releases-rust-dist",
26-
"crates/rust-toolchain",
2731
]
2832

2933
[features]
3034
default = [
3135
"rust-changelog",
3236
]
3337

38+
github = ["rust-releases-github"]
3439
rust-changelog = ["rust-releases-rust-changelog"]
3540
rust-dist = ["rust-releases-rust-dist"]
3641

3742
io = ["rust-releases-io"]
3843
io-http = ["rust-releases-io/http_client"]
3944

4045
[dependencies]
41-
rust-releases-core = { version = "^0.30.0", path = "crates/rust-releases-core" }
42-
rust-releases-io = { version = "^0.30.0", path = "crates/rust-releases-io", optional = true }
46+
# types and shared impl's
47+
rust-releases-core = { workspace = true }
48+
rust-releases-io = { workspace = true, optional = true }
49+
50+
# sources
51+
rust-releases-github = { version = "^0.30.0", path = "crates/rust-releases-github", optional = true }
4352
rust-releases-rust-changelog = { version = "^0.30.0", path = "crates/rust-releases-rust-changelog", optional = true }
4453
rust-releases-rust-dist = { version = "^0.30.0", path = "crates/rust-releases-rust-dist", optional = true }
4554

@@ -52,3 +61,8 @@ thiserror = "2.0.12"
5261

5362
# Parameterized tests
5463
yare = "3.0.0"
64+
65+
rust-release = { path = "crates/rust-release" }
66+
rust-toolchain = { version = "1.1.0", path = "crates/rust-toolchain" }
67+
rust-releases-core = { version = "^0.30.0", path = "crates/rust-releases-core" }
68+
rust-releases-io = { version = "^0.30.0", path = "crates/rust-releases-io" }

crates/rust-release/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ documentation = "https://docs.rs/rust-toolchain"
1111
repository = "https://github.com/foresterre/rust-releases"
1212

1313
[dependencies]
14-
rust-toolchain = "1.1.0"
14+
rust-toolchain = { workspace = true }
1515

1616
[dev-dependencies]
1717
yare = { workspace = true }

crates/rust-release/src/lib.rs

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
// #![deny(missing_docs)]
1515
#![warn(clippy::all)]
1616
#![deny(unsafe_code)]
17-
#![deny(missing_docs)]
17+
// #![deny(missing_docs)]
1818

1919
use crate::toolchain::ReleaseToolchain;
20+
use std::cmp::Ordering;
21+
22+
// exports
23+
pub use rust_toolchain;
24+
pub use rust_toolchain::channel::{Beta, Nightly, Stable};
2025

2126
/// Describes toolchains in so far they're relevant to a release
2227
pub mod toolchain;
@@ -25,30 +30,57 @@ pub mod toolchain;
2530
pub mod version;
2631

2732
/// Type to model a Rust release.
28-
#[derive(Clone, Debug, Eq, PartialEq)]
29-
pub struct RustRelease {
30-
version: ReleaseVersion,
31-
release_date: Option<rust_toolchain::Date>,
32-
toolchains: Vec<ReleaseToolchain>,
33+
///
34+
/// # PartialEq, Eq, Ord, PartialOrd
35+
///
36+
/// With respect to the PartialEq, Eq, PartialOrd and Ord traits, a [`RustRelease`]
37+
/// is only compared and ordered based on its `version`.
38+
#[derive(Clone, Debug)]
39+
pub struct RustRelease<V, C = ()> {
40+
pub version: V,
41+
pub release_date: Option<rust_toolchain::Date>,
42+
pub toolchains: Vec<ReleaseToolchain>,
43+
pub context: C,
44+
}
45+
46+
impl<V: PartialEq, C> PartialEq for RustRelease<V, C> {
47+
fn eq(&self, other: &Self) -> bool {
48+
self.version.eq(&other.version)
49+
}
3350
}
3451

35-
impl RustRelease {
52+
impl<V: Eq, C> Eq for RustRelease<V, C> {}
53+
54+
impl<V: PartialOrd, C> PartialOrd for RustRelease<V, C> {
55+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
56+
self.version.partial_cmp(&other.version)
57+
}
58+
}
59+
60+
impl<V: Ord, C> Ord for RustRelease<V, C> {
61+
fn cmp(&self, other: &Self) -> Ordering {
62+
self.version.cmp(&other.version)
63+
}
64+
}
65+
66+
impl<V> RustRelease<V> {
3667
/// Create a new RustRelease instance using a version, optionally
3768
/// a release date, and an iterator of toolchains.
3869
pub fn new(
39-
version: ReleaseVersion,
70+
version: V,
4071
release_date: Option<rust_toolchain::Date>,
4172
toolchains: impl IntoIterator<Item = ReleaseToolchain>,
4273
) -> Self {
4374
Self {
4475
version,
4576
release_date,
4677
toolchains: toolchains.into_iter().collect(),
78+
context: (),
4779
}
4880
}
4981

5082
/// The 3 component MAJOR.MINOR.PATCH version number of the release
51-
pub fn version(&self) -> &ReleaseVersion {
83+
pub fn version(&self) -> &V {
5284
&self.version
5385
}
5486

@@ -70,11 +102,11 @@ impl RustRelease {
70102
#[derive(Clone, Debug, Eq, PartialEq)]
71103
pub enum ReleaseVersion {
72104
/// A stable channel release version
73-
Stable(rust_toolchain::channel::Stable),
105+
Stable(Stable),
74106
/// A beta channel release version
75-
Beta(rust_toolchain::channel::Beta),
107+
Beta(Beta),
76108
/// A nightly channel release version
77-
Nightly(rust_toolchain::channel::Nightly),
109+
Nightly(Nightly),
78110
}
79111

80112
#[cfg(test)]
@@ -84,7 +116,7 @@ mod tests {
84116

85117
#[test]
86118
fn can_instantiate() {
87-
let stable_version = rust_toolchain::channel::Stable {
119+
let stable_version = Stable {
88120
version: rust_toolchain::RustVersion::new(1, 82, 0),
89121
};
90122
let version = ReleaseVersion::Stable(stable_version.clone());

crates/rust-releases-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ documentation = "https://docs.rs/rust-releases-core"
1010
repository = "https://github.com/foresterre/rust-releases"
1111

1212
[dependencies]
13+
rust-release = { workspace = true }
1314
thiserror = { workspace = true }
14-
semver = "1.0.0"
1515

1616
[dev-dependencies]
1717
yare = { workspace = true }

crates/rust-releases-core/src/channel.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
use crate::CoreError;
21
use std::convert::TryFrom;
32
use std::fmt::{Display, Formatter};
43

54
/// Enumerates the Rust release channels
65
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
76
pub enum Channel {
7+
/// An identifier for the `stable` release channel
8+
Stable,
89
/// An identifier for the `beta` release channel
910
Beta,
1011
/// An identifier for the `nightly` release channel
1112
Nightly,
12-
/// An identifier for the `stable` release channel
13-
Stable,
1413
}
1514

1615
impl TryFrom<&str> for Channel {
17-
type Error = CoreError;
16+
type Error = Error;
1817

1918
fn try_from(item: &str) -> Result<Self, Self::Error> {
2019
Ok(match item {
2120
"beta" => Self::Beta,
2221
"nightly" => Self::Nightly,
2322
"stable" => Self::Stable,
24-
unsupported => return Err(CoreError::NoSuchChannel(unsupported.to_string())),
23+
unsupported => {
24+
return Err(Error {
25+
channel: unsupported.to_string(),
26+
})
27+
}
2528
})
2629
}
2730
}
@@ -43,6 +46,12 @@ impl Display for Channel {
4346
}
4447
}
4548

49+
#[derive(Debug, thiserror::Error)]
50+
#[error("No such channel: `{}`", .channel)]
51+
pub struct Error {
52+
channel: String,
53+
}
54+
4655
#[cfg(test)]
4756
mod tests {
4857
use super::*;

crates/rust-releases-core/src/errors.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

crates/rust-releases-core/src/index.rs

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)