Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten modules by reverting back to the old module syntax #1032

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/check.rs → src/check/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::toolchain::ToolchainSpec;
use crate::rust::Toolchain;

mod rustup_toolchain_check;
#[cfg(test)]
Expand All @@ -11,5 +11,5 @@ pub use rustup_toolchain_check::{RunCommand, RustupToolchainCheck};
pub use testing::TestRunner;

pub trait Check {
fn check(&self, toolchain: &ToolchainSpec) -> TResult<Outcome>;
fn check(&self, toolchain: &Toolchain) -> TResult<Outcome>;
}
10 changes: 5 additions & 5 deletions src/check/rustup_toolchain_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::external_command::cargo_command::CargoCommand;
use crate::external_command::rustup_command::RustupCommand;
use crate::lockfile::LockfileHandler;
use crate::reporter::event::{CheckMethod, CheckResult, CheckToolchain, Method};
use crate::setup_toolchain::{SetupRustupToolchain, SetupToolchain};
use crate::toolchain::ToolchainSpec;
use crate::rust::setup_toolchain::{SetupRustupToolchain, SetupToolchain};
use crate::rust::Toolchain;
use crate::{lockfile, CargoMSRVError, Outcome, Reporter, TResult};
use camino::{Utf8Path, Utf8PathBuf};
use std::fmt;
Expand Down Expand Up @@ -38,7 +38,7 @@ impl<'reporter, 'env, R: Reporter> RustupToolchainCheck<'reporter, 'env, R> {
}

impl<'reporter, 'env, R: Reporter> Check for RustupToolchainCheck<'reporter, 'env, R> {
fn check(&self, toolchain: &ToolchainSpec) -> TResult<Outcome> {
fn check(&self, toolchain: &Toolchain) -> TResult<Outcome> {
let settings = &self.settings;

self.reporter
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<R: Reporter> fmt::Debug for RustupToolchainCheck<'_, '_, R> {
}
}

fn setup_toolchain(reporter: &impl Reporter, toolchain: &ToolchainSpec) -> TResult<()> {
fn setup_toolchain(reporter: &impl Reporter, toolchain: &Toolchain) -> TResult<()> {
let downloader = SetupRustupToolchain::new(reporter);
downloader.download(toolchain)?;

Expand All @@ -95,7 +95,7 @@ fn setup_toolchain(reporter: &impl Reporter, toolchain: &ToolchainSpec) -> TResu

fn run_check_command_via_rustup(
reporter: &impl Reporter,
toolchain: &ToolchainSpec,
toolchain: &Toolchain,
dir: &Utf8Path,
check: &[String],
) -> TResult<Outcome> {
Expand Down
8 changes: 4 additions & 4 deletions src/check/testing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::check::Check;
use crate::outcome::Outcome;
use crate::rust::Toolchain;
use crate::semver::Version;
use crate::toolchain::ToolchainSpec;
use crate::TResult;
use std::collections::HashSet;

Expand All @@ -20,18 +20,18 @@ impl TestRunner {
}

impl Check for TestRunner {
fn check(&self, toolchain: &ToolchainSpec) -> TResult<Outcome> {
fn check(&self, toolchain: &Toolchain) -> TResult<Outcome> {
let v = toolchain.version();

if self.accept_versions.contains(toolchain.version()) {
Ok(Outcome::new_success(ToolchainSpec::new(
Ok(Outcome::new_success(Toolchain::new(
v.clone(),
self.target,
&[],
)))
} else {
Ok(Outcome::new_failure(
ToolchainSpec::new(v.clone(), self.target, &[]),
Toolchain::new(v.clone(), self.target, &[]),
"f".to_string(),
))
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/context.rs → src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub mod verify;
use crate::cli::custom_check_opts::CustomCheckOpts;
use crate::cli::rust_releases_opts::Edition;
use crate::cli::{CargoMsrvOpts, SubCommand};
use crate::default_target::default_target;
use crate::log_level::LogLevel;
use crate::reporter::event::SelectedPackage;
use crate::rust::default_target::default_target;
pub use find::FindContext;
pub use list::ListContext;
pub use set::SetContext;
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 14 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,29 @@ use crate::context::ReleaseSource;
use crate::error::{CargoMSRVError, TResult};
use crate::reporter::event::{Meta, SelectedPackages, SubcommandInit};
use crate::reporter::{Event, Reporter};
use rust::release_index;
use rust_releases::semver;

pub mod check;
pub mod cli;

pub mod context;
pub mod dependency_graph;
pub mod error;
pub mod exit_code;
mod external_command;
pub mod io;
pub mod lockfile;
pub mod log_level;
pub mod manifest;
pub mod msrv;
pub mod outcome;
pub mod reporter;
pub mod toolchain;

mod context;
pub(crate) mod default_target;
pub(crate) mod dependency_graph;
mod external_command;
pub(crate) mod lockfile;
pub(crate) mod log_level;
pub(crate) mod manifest;
pub(crate) mod msrv;
pub(crate) mod outcome;
mod release_index;
pub(crate) mod releases_filter;
mod rust_release;
pub(crate) mod search_method;
pub(crate) mod setup_toolchain;
pub(crate) mod sub_command;
pub(crate) mod typed_bool;
pub(crate) mod writer;
pub mod rust;
pub mod search_method;
pub mod sub_command;
pub mod typed_bool;
pub mod writer;

pub fn run_app(ctx: &Context, reporter: &impl Reporter) -> TResult<()> {
reporter.report_event(Meta::default())?;
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/msrv.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::rust_release::RustRelease;
use crate::toolchain::ToolchainSpec;
use crate::rust::RustRelease;
use crate::rust::Toolchain;

/// An enum to represent the minimal compatibility
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum MinimumSupportedRustVersion {
/// A toolchain is compatible, if the outcome of a toolchain check results in a success
Toolchain {
// toolchain
toolchain: ToolchainSpec,
toolchain: Toolchain,
},
/// Compatibility is none, if the check on the last available toolchain fails
NoCompatibleToolchain,
Expand Down Expand Up @@ -42,7 +42,7 @@ impl MinimumSupportedRustVersion {
#[cfg(test)]
mod tests {
use crate::msrv::MinimumSupportedRustVersion;
use crate::rust_release::RustRelease;
use crate::rust::RustRelease;
use cargo_metadata::semver;

#[test]
Expand Down
18 changes: 9 additions & 9 deletions src/outcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! [`check`]: crate::check::Check

use crate::toolchain::ToolchainSpec;
use crate::rust::Toolchain;
use rust_releases::semver;

#[derive(Clone, Debug)]
Expand All @@ -12,11 +12,11 @@ pub enum Outcome {
}

impl Outcome {
pub fn new_success(toolchain_spec: ToolchainSpec) -> Self {
pub fn new_success(toolchain_spec: Toolchain) -> Self {
Self::Success(SuccessOutcome { toolchain_spec })
}

pub fn new_failure(toolchain_spec: ToolchainSpec, error_message: String) -> Self {
pub fn new_failure(toolchain_spec: Toolchain, error_message: String) -> Self {
Self::Failure(FailureOutcome {
toolchain_spec,
error_message,
Expand All @@ -37,7 +37,7 @@ impl Outcome {
}
}

pub fn toolchain_spec(&self) -> &ToolchainSpec {
pub fn toolchain_spec(&self) -> &Toolchain {
match self {
Self::Success(outcome) => &outcome.toolchain_spec,
Self::Failure(outcome) => &outcome.toolchain_spec,
Expand All @@ -47,25 +47,25 @@ impl Outcome {

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SuccessOutcome {
pub(crate) toolchain_spec: ToolchainSpec,
pub(crate) toolchain_spec: Toolchain,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FailureOutcome {
pub(crate) toolchain_spec: ToolchainSpec,
pub(crate) toolchain_spec: Toolchain,
pub(crate) error_message: String,
}

#[cfg(test)]
mod tests {
use crate::toolchain::ToolchainSpec;
use crate::rust::Toolchain;
use crate::Outcome;
use rust_releases::semver;

#[test]
fn success_outcome() {
let version = semver::Version::new(1, 2, 3);
let toolchain = ToolchainSpec::new(version, "x", &[]);
let toolchain = Toolchain::new(version, "x", &[]);

let outcome = Outcome::new_success(toolchain.clone());

Expand All @@ -77,7 +77,7 @@ mod tests {
#[test]
fn failure_outcome() {
let version = semver::Version::new(1, 2, 3);
let toolchain = ToolchainSpec::new(version, "x", &[]);
let toolchain = Toolchain::new(version, "x", &[]);

let outcome = Outcome::new_failure(toolchain.clone(), "msg".to_string());

Expand Down
8 changes: 4 additions & 4 deletions src/reporter/event/check_method.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::reporter::event::Message;
use crate::toolchain::ToolchainSpec;
use crate::rust::Toolchain;
use crate::Event;
use camino::{Utf8Path, Utf8PathBuf};

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub struct CheckMethod {
toolchain: ToolchainSpec,
toolchain: Toolchain,
method: Method,
}

impl CheckMethod {
pub fn new(toolchain: impl Into<ToolchainSpec>, method: Method) -> Self {
pub fn new(toolchain: impl Into<Toolchain>, method: Method) -> Self {
Self {
toolchain: toolchain.into(),
method,
Expand Down Expand Up @@ -65,7 +65,7 @@ mod tests {
fn reported_event(method: Method) {
let reporter = TestReporterWrapper::default();
let event = CheckMethod::new(
ToolchainSpec::new(semver::Version::new(1, 2, 3), "test_target", &[]),
Toolchain::new(semver::Version::new(1, 2, 3), "test_target", &[]),
method,
);

Expand Down
12 changes: 6 additions & 6 deletions src/reporter/event/check_result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::reporter::event::shared::compatibility::Compatibility;
use crate::reporter::event::Message;
use crate::toolchain::ToolchainSpec;
use crate::rust::Toolchain;
use crate::Event;

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
Expand All @@ -11,19 +11,19 @@ pub struct CheckResult {
}

impl CheckResult {
pub fn compatible(toolchain: impl Into<ToolchainSpec>) -> Self {
pub fn compatible(toolchain: impl Into<Toolchain>) -> Self {
Self {
compatibility: Compatibility::compatible(toolchain),
}
}

pub fn incompatible(toolchain: impl Into<ToolchainSpec>, error: Option<String>) -> Self {
pub fn incompatible(toolchain: impl Into<Toolchain>, error: Option<String>) -> Self {
Self {
compatibility: Compatibility::incompatible(toolchain, error),
}
}

pub fn toolchain(&self) -> &ToolchainSpec {
pub fn toolchain(&self) -> &Toolchain {
self.compatibility.toolchain()
}

Expand All @@ -49,7 +49,7 @@ mod tests {
#[test]
fn reported_compatible_toolchain() {
let reporter = TestReporterWrapper::default();
let event = CheckResult::compatible(ToolchainSpec::new(
let event = CheckResult::compatible(Toolchain::new(
semver::Version::new(1, 2, 3),
"test_target",
&[],
Expand All @@ -70,7 +70,7 @@ mod tests {
fn reported_incompatible_toolchain(error_message: Option<String>) {
let reporter = TestReporterWrapper::default();
let event = CheckResult::incompatible(
ToolchainSpec::new(semver::Version::new(1, 2, 3), "test_target", &[]),
Toolchain::new(semver::Version::new(1, 2, 3), "test_target", &[]),
error_message,
);

Expand Down
8 changes: 4 additions & 4 deletions src/reporter/event/check_toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::reporter::event::Message;
use crate::toolchain::ToolchainSpec;
use crate::rust::Toolchain;
use crate::Event;

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub struct CheckToolchain {
pub toolchain: ToolchainSpec,
pub toolchain: Toolchain,
}

impl CheckToolchain {
pub fn new(toolchain: impl Into<ToolchainSpec>) -> Self {
pub fn new(toolchain: impl Into<Toolchain>) -> Self {
Self {
toolchain: toolchain.into(),
}
Expand All @@ -33,7 +33,7 @@ mod tests {
#[test]
fn reported_event() {
let reporter = TestReporterWrapper::default();
let event = CheckToolchain::new(ToolchainSpec::new(
let event = CheckToolchain::new(Toolchain::new(
semver::Version::new(1, 2, 3),
"test_target",
&[],
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/reporter/event/setup_toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::reporter::event::Message;
use crate::toolchain::ToolchainSpec;
use crate::rust::Toolchain;
use crate::Event;

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub struct SetupToolchain {
toolchain: ToolchainSpec,
toolchain: Toolchain,
}

impl SetupToolchain {
pub fn new(toolchain: impl Into<ToolchainSpec>) -> Self {
pub fn new(toolchain: impl Into<Toolchain>) -> Self {
Self {
toolchain: toolchain.into(),
}
Expand All @@ -33,7 +33,7 @@ mod tests {
#[test]
fn reported_event() {
let reporter = TestReporterWrapper::default();
let event = SetupToolchain::new(ToolchainSpec::new(
let event = SetupToolchain::new(Toolchain::new(
semver::Version::new(1, 2, 3),
"test_target",
&[],
Expand Down
Loading
Loading