diff --git a/crates/pacdef_core/src/backend/actual/rustup/helpers.rs b/crates/pacdef_core/src/backend/actual/rustup/helpers.rs index 503fd83..94c6825 100644 --- a/crates/pacdef_core/src/backend/actual/rustup/helpers.rs +++ b/crates/pacdef_core/src/backend/actual/rustup/helpers.rs @@ -1,4 +1,4 @@ -use super::types::{Repotype, RustupPackage}; +use super::types::RustupPackage; pub fn toolchain_of_component_was_already_removed( removed_toolchains: &[String], @@ -7,22 +7,6 @@ pub fn toolchain_of_component_was_already_removed( removed_toolchains.contains(&component.toolchain) } -pub fn sort_packages_into_toolchains_and_components( - packages: Vec, -) -> (Vec, Vec) { - let mut toolchains = vec![]; - let mut components = vec![]; - - for package in packages { - match package.repotype { - Repotype::Toolchain => toolchains.push(package), - Repotype::Component => components.push(package), - } - } - - (toolchains, components) -} - pub fn install_components(line: &str, toolchain: &str, val: &mut Vec) { let mut chunks = line.splitn(3, '-'); let component = chunks.next().expect("Component name is empty!"); @@ -61,6 +45,7 @@ pub fn group_components_by_toolchains(components: Vec) -> Vec Self { - Self { - packages: HashSet::new(), - } - } - fn run_component_command(&self, args: &[&str], toolchains: &[String]) -> Result> { let mut val = Vec::new(); @@ -103,7 +100,7 @@ impl Rustup { let output = String::from_utf8(cmd.output()?.stdout)?; for component in output.lines() { - helpers::install_components(component, toolchain, &mut val); + install_components(component, toolchain, &mut val); } } @@ -150,7 +147,7 @@ impl Rustup { return Ok(()); } - let components_by_toolchain = helpers::group_components_by_toolchains(components); + let components_by_toolchain = group_components_by_toolchains(components); for components_for_one_toolchain in components_by_toolchain { let mut cmd = Command::new(self.get_binary()); @@ -206,10 +203,7 @@ impl Rustup { let mut cmd = Command::new(self.get_binary()); cmd.args(Repotype::Component.get_remove_switches()); - if helpers::toolchain_of_component_was_already_removed( - &removed_toolchains, - &component_package, - ) { + if toolchain_of_component_was_already_removed(&removed_toolchains, &component_package) { continue; } diff --git a/crates/pacdef_core/src/backend/actual/rustup/types.rs b/crates/pacdef_core/src/backend/actual/rustup/types.rs index c2f62c3..17ecdee 100644 --- a/crates/pacdef_core/src/backend/actual/rustup/types.rs +++ b/crates/pacdef_core/src/backend/actual/rustup/types.rs @@ -14,6 +14,28 @@ pub enum Repotype { Component, } +/// A package as used exclusively in the rustup backend. Contrary to other packages, this does not +/// have an (optional) repository and a name, but is either a component or a toolchain, has a +/// toolchain version, and if it is a toolchain also a name. +#[derive(Debug)] +pub struct RustupPackage { + /// Whether it is a toolchain or a component. + pub repotype: Repotype, + /// The name of the toolchain this belongs to (stable, nightly, a pinned version) + pub toolchain: String, + /// If it is a toolchain, it will not have a component name. + /// If it is a component, this will be its name. + pub component: Option, +} + +impl Rustup { + pub fn new() -> Self { + Self { + packages: HashSet::new(), + } + } +} + impl Repotype { fn try_from(value: T) -> Result where @@ -50,20 +72,6 @@ impl Repotype { } } -/// A package as used exclusively in the rustup backend. Contrary to other packages, this does not -/// have an (optional) repository and a name, but is either a component or a toolchain, has a -/// toolchain version, and if it is a toolchain also a name. -#[derive(Debug)] -pub struct RustupPackage { - /// Whether it is a toolchain or a component. - pub repotype: Repotype, - /// The name of the toolchain this belongs to (stable, nightly, a pinned version) - pub toolchain: String, - /// If it is a toolchain, it will not have a component name. - /// If it is a component, this will be its name. - pub component: Option, -} - impl RustupPackage { /// Creates a new [`RustupPackage`]. /// @@ -85,6 +93,22 @@ impl RustupPackage { } } + pub fn sort_packages_into_toolchains_and_components( + packages: Vec, + ) -> (Vec, Vec) { + let mut toolchains = vec![]; + let mut components = vec![]; + + for package in packages { + match package.repotype { + Repotype::Toolchain => toolchains.push(package), + Repotype::Component => components.push(package), + } + } + + (toolchains, components) + } + pub fn from_pacdef_packages(packages: &[Package]) -> Result> { let mut result = vec![];